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:

power bi

When I select 2021, it will give me the result of 2021 and same thing for 2022:

power bi power bi

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:

power bi

I will create a measure and put my formula:

power bi

And this is the result:

power bi power bi

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:

power bi

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")

power bi

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]))

power bi

And this is the result:

power bi power bi

Interesting Management