Forum Discussion
Rank orders by value with multiple lines per order
- 5 years ago
Anonymous
You can try this one. I suspect it's now doing what you wanted...
Sales BG2 = var CurrentlyVisibleGroups = DISTINCT( 'Order Groups'[Group] ) var CurrentlyVisibleOrders = DISTINCT( SalesOrders[OrderNo] ) var OrdersInCurrentlyVisibleGroups = CALCULATETABLE( var AllOrders = DISTINCT( SalesOrders[OrderNo] ) return FILTER( CurrentlyVisibleOrders, var OrderRank = RANKX( AllOrders, [Sales],, DESC ) var OrderGroup = MAXX( FILTER( 'Order Groups', 'Order Groups'[Min] < OrderRank && OrderRank <= 'Order Groups'[Max] ), 'Order Groups'[Group] ) return OrderGroup in CurrentlyVisibleGroups ), ALLEXCEPT( SalesOrders, 'Date' ), // This directive should let you only rank // against orders that are relative to // all the visible products, visible // somewhere in your visual, not necessarily // just in the cell being evaluated. ALLSELECTED( 'Products' ) ) var Result = CALCULATE( [Sales], OrdersInCurrentlyVisibleGroups ) return ResultBear in mind that 'Products' must be a dimension connected to your fact table 'SalesOrders'. And you should never slice in the UI by the columns of your fact tables. Only via dimensions. If you don't follow this rule... you'll be in trouble sooner or later. I tell you today.
daxer-almighty that almost did it .. I think I got it fixed by changing the ALLEXCEPT( SalesOrders, 'Date' ) for ALLSELECTED( SalesOrders).
Thanks for all your help.
Good you got it working exactly as you wanted. Sorry I was not able to address this problem immediately but I did not fully understand how this measure should behave in all possible contexts.
- Anonymous5 years agoNot applicable
You did great and put me on the right direction .. thanks for your help.