I am attempting to create a slicer, which would switch between measures in a visual.
Due to some limitations, I'm not using Field parameter. Instead, I'm using a measure name table + DAX expression used as value in visual, meant to switch between measure.
Issue I'm facing:
For some cases, I need to show two measures in a visual, with legend for each measure. If i simply select two measures in slicer, I'm getting a sum of two measures.
Is this possible to achieve?
Current DAX expression two switch between measures:
Selected Measure =
IF (
HASONEVALUE ( 'Measures Table'[Measure] ),
SWITCH (
VALUES ( 'Measures Table'[Measure] ),
"Total", [Total],
"New", [New] ,
"Direct", [Direct],
"Indirect", [Indirect]
),
[Total]
)
How do I combine "Direct" and "Indirect" in one slicer position, to display both measures in visual with legend?
Related
I have a slicer, called COUNTRY and applied to table MY_TABLE. When I calculate a measure, everything works as expected:
-- calculates distinct count only for COUNTRY = x
Some Measure = DISTINCTCOUNT('MY_TABLE'[SOME_COLUMN])
The problem is SUMMARIZE ignores slicer selection:
-- calculates distinct count accross all countries: x, y, z, etc.
Calculated Table =
RETURN SUMMARIZE(
'SOME_TABLE',
[CATEGORY],
"COUNT", DISTINCTCOUNT('SOME_TABLE'[SOME_COLUMN])
)
How to make SUMMARIZE take into account slicers?
Only Measures are "responsive", calculated tables and columns get calculated and created once, when the data are loaded.
Note that if a calculated table is used inside a measure it will behave correctly, but as you may know, a measure must return a scalar value and not a table. (ie you can use summarize inside a measure, you can then filter the obtained table and return the sum of one column)
Of course, you can filter calculated table with a slicer. If you can, go for SUMMARIZECOLUMNS because this function is better optimized then SUMMARIZE, and has arguments for filtering.
Filtering SUMMARIZECOLUMNS
If you want to stick to SUMMARIZE, you can filter your table by wrapping it with CALCULATETABLE.
Calculated Table =
CALCULATETABLE (
SUMMARIZE (
'SOME_TABLE',
[CATEGORY],
"COUNT", DISTINCTCOUNT ( 'SOME_TABLE'[SOME_COLUMN] )
),
Dim[Color]
= SELECTEDVALUE ( Slicer[SlicerValues] )
)
Should FILTER be used inside or outside of SUMMARIZE?
I have a table with columns 'date from' and 'date to', and visualize them as bars using asTimeline visual.
I want to add a slicer which will work on both of these fields simultaneously. Currently I have two slicers working independently on each of those fields:
This is not really intuitive. Since start and end both define a period in time, if the period is inside the slider selection, it should be included. But slicers work on only one field. So I probably need to perform some DAX magic to create a field based on those two, but I don't know where to begin.
First create an measure to check a row overlaps the your date range:
Date Included =
IF (
FIRSTNONBLANK ( DateTable[Start Date], 1 ) <= MAX ( 'Calendar'[Date] ) &&
FIRSTNONBLANK( DateTable[End Date], 1 ) >= MIN ( 'Calendar'[Date] ),
"Include",
"Exclude"
)
and , add above Measure as a filter on your visualisation, where Date Included is Include
Than you can filter your Calendar table to single value, or range.
Also,only overlapping rows from your fact table will be displayed.
The problem can be solved by using a separate calendar-table and a measure: PowerBI filter- selected Date between Start and End date
Another way to solve this, and keep using the two slicers more intuitively, is described here: https://radacad.com/from-and-to-date-slicers-in-power-bi-filtering-based-on-two-fields. The solution describes how to set the properties of those timeline-slicers so that it makes a bit more sense for the user (set the "Start of employment" slicer as Type - After and the "End of employment" as Type - Before).
In Power BI you can have multiple slicers based on different criteria in the data, e.g. one on shape and one on colour. The interaction between or among these slicers means that if I were to select "circle" and "red" then the results would be about red circles only. It filters to those entries where BOTH slicers are met. Is there a way to set Power BI slicers so that if I selected "circle" and "red" I would get both all red and all circle results (e.g. only one slicer needs to be satisfied)?
Here I'd like to get rows 1,4,5,6 returned.
Any help would be hugely appreciated!
Edited. As Alexis points out in the comments, I had this wrong at first. Thanks for the gentle nudge!
EitherCondition =
VAR MatchesColour =
CALCULATE (
COUNTROWS ( 'FactTable' ),
KEEPFILTERS ( TREATAS ( VALUES ( 'ColoursDisconnected'[Colour] ), 'Colours'[Colour] ) )
) > 0
VAR MatchesShape =
CALCULATE (
COUNTROWS ( 'FactTable' ),
KEEPFILTERS ( TREATAS ( VALUES ( 'ShapesDisconnected'[Shape] ), 'Shapes'[Shape] ) )
) > 0
RETURN
MatchesColour || MatchesShape
With no other details of your data model, I'm assuming a simple dimensional model with a 'Colours' dimension of unique colours and a 'Shapes' dimension of unique shapes, each connected in a 1:N relationship with a fact table named 'FactTable'. As Alexis pointed out in comments, to drive this behavior, we need to build disconnected tables to drive the slicers.
Thus we have slicers populated from disconnected tables, and we have the table visual created with the related dimensions.
The first VAR says whether there is any data in the fact based on diconnected colour context. The second does the same for shape. If either is true, we return TRUE.
You can filter your visual on [EitherCondition]=True to remove the other values. Or you could build from here into a more complex measure.
The key part is that filter context in DAX is always a logical AND situation. The only way to get logical ORs is to evaluate multiple expressions and come up with a way to combine them that works in your situation.
Here's the model diagram:
And the measure in action:
I have a running total dax measure that works. Problem now is that the slicer on the page is coming from another data set which is linked to the source table of running total data set and when you select the slicer it doesn't filter anything.
Homes Connected =
CALCULATE (
SUM ( refv_FTTH_HomesConnected[ActualHomesConnected] ),
FILTER ( ALL ( refv_FTTH_HomesConnected ), refv_FTTH_HomesConnected[Month_sort2] <= MAX ( refv_FTTH_HomesConnected[Month_sort2] ) )
)
Is there a way to incorporate the columns from the other dataset to get the desired result?
The ALL in your FILTER removes any slicer selection filtering.
Try using ALLSELECTED instead.
Within Power BI Desktop (Version: 2.39.4526.362 64-bit (September 2016), I have written a DAX Statement that behaves differently when the column is sorted by another vs when it is not sorted by another.
Measure:
Sum of Sales Across All Months =
CALCULATE ( SUM ( SalesAmount ), ALL ( 'Date'[MonthName] ) )
When the MonthName column is unsorted by another column, the measure behaves as I expect. Eliminating the filter context of the MonthName column. However, as soon as I set the MonthName column to be sorted by another column (e.g., MonthNumber) the "ALL" context reset is lost and it reverts back to the MonthName context.
Does anyone know if this is a bug or if I am misunderstanding something?
Thanks!
When one column sorts by another column, the DAX that Power BI generates includes the sort-by column, even though it's not visible in your visual. Therefore, for the measure to behave as you'd expect, you need to remove the filter context from both columns, even though only one is visible:
Sum of Sales Across All Months =
CALCULATE (
SUM ( SalesAmount ),
ALL ( 'Date'[MonthName] ),
ALL ( 'Date'[MonthNumber] )
)
It's unintuitive, but I don't know that it's a bug. There's a blog post that describes the behaviour you're seeing here: https://blog.crossjoin.co.uk/2015/12/15/power-bi-desktop-sort-by-column-and-dax-calculations-that-use-the-all-function/