Power BI: customized result when select a specific value of a filter
When I use a slicer, it may happen that what I want it is that when I select a particular value, I want to display a personalized result. Let´s take an example, I have this data:
When I select 2021, it will give me the result of 2021 and same thing for 2022:
But what I have to do if I select 2021 and I want to show something else. In this case, I will have to use the combination of IF and SELECTEDVALUE functions so the formula is:
IF(SELECTEDVALUE('table'[argument])=value,custom-result1,custom-result2)
The “'table'[argument]” should be the one you use for your filter. For my example, my filter is:
I will create a measure and put my formula:
And this is the result:
The only thing to take in account it is the format of your argument that you will use for your filter, based on that, the “value” for SELECTEDVALUE should be put between quotes or not:
- value: without quotes if “date” or “number”
- "value": with quotes if “text”
In my example, the “[Date]” is formatted as “date” so there are no quotes but imagine that the “[Date]” is formatted as “text” so the formula will be:
If for some reasons, I want to cancel the filter in spite that I use SELECTEDVALUE, in such situation, I will combine the CALCULATE function and this criteria:
- ALL('table'[argument])
The “'table'[argument]” should be the one you use for your filter. Let´s put in practice, currently, my formula for P1:
CALCULATE(COUNT('table'[argument1]),'table'[argument2]="value")
And for P2, the formula is the same except instead of "P1" it is "P2". With this formula, as you can see above, when I select 2021, it gives me 630 for P1 and 2493 for P2. Now, what I want it is that in spite that I select 2021, I want to calculate everything as if no filter has been used, the formula will be:
CALCULATE(P1 formula, ALL('table'[argument3]))
And this is the result:
Interesting Topics
-
Be successfully certified ITIL 4 Managing Professional
Study, study and study, I couldn’t be successfully certified without studying it, if you are interested...
-
Be successfully certified ITIL 4 Strategic Leader
With my ITIL 4 Managing Professional certification (ITIL MP) in the pocket, it was time to go for the...
-
Hide visual and change background color based on selection
Some small tricks to customize the background colour of a text box...
-
Stacked and clustered column chart or double stacked column chart
In excel, I use a lot the combination of clustered and stacked chart...