I couldn't visualize what is PowerBI doing with the COUNTROW function behind the below DAX formula. If I don't include COUNTROW, the formula would return an error as it was unable to return a scalar value.
My understanding with the formula is, Power BI will return a table with a set of unique customer names, run the filter on whether the customers matches the two criteria, and finally return the total sales for each customer in the table if it matches the criteria. I couldn't visualize what COUNTROW is doing or returning in this case.
COUNTROWS is checking if the FITLER inside is returning any row and if COUNTROWS is 0 then that ROW isn't returned by FILTER for the CALCULATE, in simple words, FILTER ( VALUES ( Customer[Customer Name] ) .....) construct iterates for each customer and checks wheter the count of rows returned by the inner FILTER is greater than 0 and if it is greater than 0 then keep that customer otherwise remove it from the list once everything is computed outer FILTER returns only CustomerNames that have atleast 1 row in Outlier table and then CALCULATE pushes this list into the filter context and then evaluates [Total Sales]
Hi @AntrikshSharma ,
Thank you so much for your clear explanation. Could you enlighten me why the formula is unable to return a scalar value if I don't include COUNTROW in the formula? Why would there be multiple columns?
Because when you remove COUNTROWS you are removing aggregation and the second part of FILTER is for specifying conditions/boolean operations because of which FILTER is able reduce the number of rows returned by it. Also, I just realised that you should insert CALCULATE before COUNTROWS so that the Outliers related to the customers can be counted
Outlier Sales = CALCULATE ( [Total Sales], FILTER ( VALUES ( Customers[Customer Names] ), CALCULATE ( COUNTROWS ( 'Outlier Detection Logic' ), FILTER ( 'Outlier Detection Logic', [Profit Margin] >= 'Outlier Detection Logic'[Profit Margins Min] && [Total Sales] >= 'Outlier Detection Logic'[Profit Margins Min] ) ) > 0 ) )
Hi @kimjongbun ,
Have a look at this to understand Count Rows.
Appreciate with a Kudos!! (Click the Thumbs Up Button)
Did I answer your question? Mark my post as a solution!
Hi @AntrikshSharma ,
Am I correct to say that DAX is using the following sequence to get to the solution? Bold and Italic are the booleans / measure, and the number in the blue circle is the sequence in which DAX is following.
Find your favorite faces from the community presenting at the Power Platform Community Conference!
See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.
Join this community-driven Power Platform digital event for unbiased support and problem-solving.