Forum Discussion
Filtering a constant value
Hello,
I am new to Power BI, so my question is that why this measure example returns 3 rows in a table, while I expected it to return only 1 row. I do not understand how to filter constant values. Thank you.
Best regards,
André
Hi, afbraga66 ,
According to offical document, CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])https://docs.microsoft.com/en-us/dax/calculate-function-dax
Calculate ([column]) or average or count... as 1 is a constant.so we could change it to:Measure = IF(MAX('Dim_PLANT'[Plant_Code])="P058",1)The final show:
Or
Measure 2 = CALCULATE(COUNT(Dim_PLANT[Plant_Code]),FILTER('Dim_PLANT',[Plant_Code]="P058"))The final show:
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
7 Replies
- afbraga66Helper III
Same, doesn't work.
- tamerj1Community Champion
- tamerj1Community Champion
CALCULATE replaces the filter with the new filter inside it. So it replaces P051 with P059 and so on for all plant codes. What I don't understand why the KEEPFILTERS function didn't work with constant value as it KEEPFILTERS keeps the original filter and the intersection between the old the new filter leaves blank tables at all plant codes except P059.
With SUMX we manually return blank if the code is not P059
- vapid128Solution Specialist
You are calculating 1, in whatever case.
It gives you back 1.
If you calculat a measure like countrows(table), and the countrows filter by case
then it will get different numbers.
- v-yalanwu-msftCommunity Support
Hi, afbraga66 ,
According to offical document, CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])https://docs.microsoft.com/en-us/dax/calculate-function-dax
Calculate ([column]) or average or count... as 1 is a constant.so we could change it to:Measure = IF(MAX('Dim_PLANT'[Plant_Code])="P058",1)The final show:
Or
Measure 2 = CALCULATE(COUNT(Dim_PLANT[Plant_Code]),FILTER('Dim_PLANT',[Plant_Code]="P058"))The final show:
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.