Forum Discussion
#1 HELP_DAX RANKX Function Strange issue
- 8 years ago
HI _google
Try adding these two calculated columns to your table
Rank of Product = CALCULATE( COUNTROWS('fUnits') , FILTER( ALL(fUnits) , 'fUnits'[Profit] > EARLIER('fUnits'[Profit]) ) ) +1Rank of Product by Manufacturer = CALCULATE( COUNTROWS('fUnits') , FILTER( ALL(fUnits) , 'fUnits'[Manufacturer] = EARLIER('fUnits'[Manufacturer]) && 'fUnits'[Profit] > EARLIER('fUnits'[Profit]) ) ) +1 - 8 years ago
Hi _google
Did you add these as calculated columns?
Here is a link to a simplified version of the PBIX file with both calculated columns added.
https://1drv.ms/u/s!AtDlC2rep7a-oirt55D4GDKunVSc
- 8 years ago
Hi,
You may download my solution from here. This has been done in MS Excel using the PowerPivot but can also be done in PowerBI desktop. You may also import all the data and the formulas from this Excel file directly into PowerBI desktop by going to File > Import in PowerBI desktop.
Hope this helps.
- 8 years ago
Hi Phil
Thanks for the solution, it work with calculated column, I was trying to do it through a measure however it helps on learning curve with DAX
regards
HI _google
Try adding these two calculated columns to your table
Rank of Product =
CALCULATE(
COUNTROWS('fUnits') ,
FILTER(
ALL(fUnits) ,
'fUnits'[Profit] > EARLIER('fUnits'[Profit])
)
) +1Rank of Product by Manufacturer =
CALCULATE(
COUNTROWS('fUnits') ,
FILTER(
ALL(fUnits) ,
'fUnits'[Manufacturer] = EARLIER('fUnits'[Manufacturer]) &&
'fUnits'[Profit] > EARLIER('fUnits'[Profit])
)
) +1HI _google
Try this MEASURE for ranking Total Profit
Rank Total Profit by Product SUM =
RANKX (
SUMMARIZE ( ALLSELECTED ( fUnits ), fUnits[Manufacturer], fUnits[Product] ),
CALCULATE ( SUM ( fUnits[Profit] ) ),
,
DESC,
DENSE
)
- Zubair_Muhammad8 years agoCommunity Champion
And this MEASURE for ranking Total Profit by Product within each Manufacturer
Rank Total Profit by Product within Manuf = RANKX ( SUMMARIZE ( FILTER ( ALLSELECTED ( fUnits ), fUnits[Manufacturer] = SELECTEDVALUE ( fUnits[Manufacturer] ) ), fUnits[Manufacturer], fUnits[Product] ), CALCULATE ( SUM ( fUnits[Profit] ) ), , DESC, DENSE )