Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
newyearrrr
Frequent Visitor

could you help me dynamic ranking data with measure

------- > for power bi file example data 

i have data table like this :

newyearrrr_0-1715161378945.png

 

and I want to sort the data dynamically with this measure. (Card A shown in the picture below)

A = CALCULATESUM('03Data'[VALUE_(MB)] ) , 
        FILTER('03Data','03Data'[GROUP] = "Forecast",
 ALLEXCEPT('03Data_FruitExport_LOT','03Data_FruitExport_LOT'[COUNTRY] )))

newyearrrr_1-1715160347405.png

if card A >= 0 , I want to sort them from positive to negative ( by FC_index01 : from + to - )
but if card A < 0 , I want to sort them from negative to positive ( by FC_index02 : from - to + )


I tried but couldn't.
Sometimes the sorting will be wrong when I select the filter Export_Fruit.



------- > for power bi file example data

2 ACCEPTED SOLUTIONS
Alex87
Solution Sage
Solution Sage

Hello,

 

I changed your slicer export fruit to come from Table 2. idem Country from Table

I reviewed your formulas:

 

 

 

_Rank1 = 
RANKX(
    ALLSELECTED('03Data'),
    CALCULATE(SUM('03Data'[VALUE_(MB)])),
    ,
    ASC,
    Dense
)

_Rank2 = 
RANKX(
    ALLSELECTED('03Data'),
    CALCULATE(SUM('03Data'[VALUE_(MB)])),
    ,
    DESC,
    Dense
)

SortSolution = 
VAR _SelectedFruit = SELECTEDVALUE(Table2[EXPORT_FRUIT])
VAR _IsSelectedFuit = ISFILTERED(Table2[EXPORT_FRUIT])
VAR _SelectedCountry = SELECTEDVALUE('Table'[COUNTRY])
VAR _IsSelectedCountry = ISFILTERED('Table'[COUNTRY])
VAR _Value = 
SWITCH(
    TRUE(),
    _IsSelectedFuit && NOT(_IsSelectedCountry), CALCULATE([SUMVAL_FC], ALL('03Data'[COUNTRY]), ALL('03Data'[COUNTRY : LOT]), '03Data'[EXPORT_FRUIT] = _SelectedFruit),
    _IsSelectedFuit && _IsSelectedCountry, CALCULATE([SUMVAL_FC], ALL('03Data'[COUNTRY]), ALL('03Data'[COUNTRY : LOT]),'03Data'[COUNTRY] = _SelectedCountry, '03Data'[EXPORT_FRUIT] = _SelectedFruit),
    NOT(_IsSelectedFuit) && _IsSelectedCountry, CALCULATE([SUMVAL_FC], ALL('03Data'),ALL('03Data'[COUNTRY : LOT]),'03Data'[COUNTRY] = _SelectedCountry),
    CALCULATE([SUMVAL_FC], ALL('03Data'[COUNTRY : LOT]), ALL('03Data'[EXPORT_FRUIT]))) 


VAR _Result = 
IF(_Value>=0, [_Rank2],[_Rank1])

RETURN
_Result

 

 

 

Alex87_0-1715175147220.png

Alex87_1-1715175183215.png

 

you can filter our in the graph the 0 values that are not useful

Alex87_2-1715177660616.png

If it answers your question, please mark my reply as the solution. Thanks

 




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!




View solution in original post

thats work ! Thank you for your help.

View solution in original post

2 REPLIES 2
Alex87
Solution Sage
Solution Sage

Hello,

 

I changed your slicer export fruit to come from Table 2. idem Country from Table

I reviewed your formulas:

 

 

 

_Rank1 = 
RANKX(
    ALLSELECTED('03Data'),
    CALCULATE(SUM('03Data'[VALUE_(MB)])),
    ,
    ASC,
    Dense
)

_Rank2 = 
RANKX(
    ALLSELECTED('03Data'),
    CALCULATE(SUM('03Data'[VALUE_(MB)])),
    ,
    DESC,
    Dense
)

SortSolution = 
VAR _SelectedFruit = SELECTEDVALUE(Table2[EXPORT_FRUIT])
VAR _IsSelectedFuit = ISFILTERED(Table2[EXPORT_FRUIT])
VAR _SelectedCountry = SELECTEDVALUE('Table'[COUNTRY])
VAR _IsSelectedCountry = ISFILTERED('Table'[COUNTRY])
VAR _Value = 
SWITCH(
    TRUE(),
    _IsSelectedFuit && NOT(_IsSelectedCountry), CALCULATE([SUMVAL_FC], ALL('03Data'[COUNTRY]), ALL('03Data'[COUNTRY : LOT]), '03Data'[EXPORT_FRUIT] = _SelectedFruit),
    _IsSelectedFuit && _IsSelectedCountry, CALCULATE([SUMVAL_FC], ALL('03Data'[COUNTRY]), ALL('03Data'[COUNTRY : LOT]),'03Data'[COUNTRY] = _SelectedCountry, '03Data'[EXPORT_FRUIT] = _SelectedFruit),
    NOT(_IsSelectedFuit) && _IsSelectedCountry, CALCULATE([SUMVAL_FC], ALL('03Data'),ALL('03Data'[COUNTRY : LOT]),'03Data'[COUNTRY] = _SelectedCountry),
    CALCULATE([SUMVAL_FC], ALL('03Data'[COUNTRY : LOT]), ALL('03Data'[EXPORT_FRUIT]))) 


VAR _Result = 
IF(_Value>=0, [_Rank2],[_Rank1])

RETURN
_Result

 

 

 

Alex87_0-1715175147220.png

Alex87_1-1715175183215.png

 

you can filter our in the graph the 0 values that are not useful

Alex87_2-1715177660616.png

If it answers your question, please mark my reply as the solution. Thanks

 




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!




thats work ! Thank you for your help.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.