a) Role of countrows in the above DAX.
b) How is outer filter function getting connected with inner filter function.
c) What is the output of inner filter function.
d) RANKX( ALL( Customers[Customer Name] ), [Total Profits], DESC ) . Is ALL fetching list of unique result ,if yes isnt the customer name should have one value at the level as it is getting iterated from the outer filter function FILTER( VALUES( Customers[Customer Name] ),
@Kartic21
I made some notes in the function itself, see if that helps:
Customer Group Profits =
/* Things to remember:
1. Generally better to look at the functions inside out, rather than outside in
2. FILTERS are iterators
3. Filters are tables
*/
/* Aggregating the Total Profits happens at the very end*/
CALCULATE(
[Total Profits],
/* We are going to filter the customer Names */
FILTER(
VALUES( Customers[Customer Name] ),
/* You set a variable here for the customer rank to make the code easier to follow and probably a performance benefit too
but need to set the variable after you started iterating the Customers [Customer Name] column
Need to use ALL here to remove any filters from Customer Name, otherwise you will be comparing the current customer's total profit to itseld, which will always be one
*/
VAR __CustomerRank=
RANKX( ALL( Customers[Customer Name] ), [Total Profits],, DESC )
RETURN
/* This will return one row, the customer group, since the customer rank can only be in group. Could have easily been =1 instead of >0
So as we iterate through each customer we "know" what customer group they belong to based on their rank*/
COUNTROWS(
FILTER(
'Customer Groups',
__CustomerRank > 'Customer Groups'[Min]
&& __CustomerRank <= 'Customer Groups'[Max]
)
)
> 0
)
)
The “Mastering DAX calculations” module would be a good place to start. Context appears to be pretty simple ( and in theory it is) but it becomes much more complex as you get deeper into DAX.