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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
_Loic
New Member

Formula problem Rank

Hi,

I try this Measure

_Cumul_III =
    Var Mon_Numero = RANKX(ALLSELECTED(Produits[PRO_CODE]),[_Marges_2])
    Var Best_Products = TOPN(Mon_Numero,'Produits',[_Marges_2])
    Var My_Sum = CALCULATE([_Marges_2],Best_Products)
    RETURN My_Sum
 I want to sum the [_Marges_2] for the ranking :
for example If the rank is 2 : 16 248 988.14 + 14 230 309.54
but my measure give only : 14 230 310
Can you explain to me the reason ?
thanks a lot
_Loic_0-1701860280365.png

 

1 ACCEPTED SOLUTION

@_Loic Let's try a different approach:
_Cumul_III =
VAR CurrentProduct = SELECTEDVALUE(Produits[PRO_CODE])
VAR Mon_Numero = RANKX(ALLSELECTED(Produits[PRO_CODE]), [_Marges_2], , DESC, Dense)
VAR My_Sum =
CALCULATE(
SUM([_Marges_2]),
FILTER(
ALL(Produits[PRO_CODE]),
RANKX(ALLSELECTED(Produits[PRO_CODE]), [_Marges_2], , DESC, Dense) <= Mon_Numero &&
SELECTEDVALUE(Produits[PRO_CODE]) = CurrentProduct
)
)
RETURN My_Sum

BBF

View solution in original post

5 REPLIES 5
Loic_Pedro_Hans
Regular Visitor

Hello BBF,

Really great ! 

it works perfectly !!

Thanks .

@Loic_Pedro_Hans  accept the correct answear as a solution please.

 

BBF

BeaBF
Super User
Super User

@_Loic  Hi!
Try with:

_Cumul_III =
VAR Mon_Numero = RANKX(ALLSELECTED(Produits[PRO_CODE]), [_Marges_2], , DESC, Dense)
VAR SelectedProducts = TOPN(Mon_Numero, VALUES(Produits[PRO_CODE]), [_Marges_2], DESC)
VAR My_Sum = CALCULATE(SUM([_Marges_2]), FILTER(ALL(Produits[PRO_CODE]), RANKX(ALLSELECTED(Produits[PRO_CODE]), [_Marges_2], , DESC, Dense) <= Mon_Numero))
RETURN My_Sum

BBF

Thanks a lot,

Your code is interesting, better than me.

But i have the same result ...

_Cumul_IV =
VAR Mon_Numero = RANKX(ALLSELECTED(Produits[PRO_CODE]), [_Marges_2], , DESC, Dense)
VAR SelectedProducts = TOPN(Mon_Numero, VALUES(Produits[PRO_CODE]), [_Marges_2], DESC)
VAR My_Sum = CALCULATE([_Marges_2], FILTER(ALL(Produits[PRO_CODE]), RANKX(ALLSELECTED(Produits[PRO_CODE]), [_Marges_2], , DESC, Dense) <= Mon_Numero))
RETURN My_Sum
_Loic_0-1701875842692.png

 

@_Loic Let's try a different approach:
_Cumul_III =
VAR CurrentProduct = SELECTEDVALUE(Produits[PRO_CODE])
VAR Mon_Numero = RANKX(ALLSELECTED(Produits[PRO_CODE]), [_Marges_2], , DESC, Dense)
VAR My_Sum =
CALCULATE(
SUM([_Marges_2]),
FILTER(
ALL(Produits[PRO_CODE]),
RANKX(ALLSELECTED(Produits[PRO_CODE]), [_Marges_2], , DESC, Dense) <= Mon_Numero &&
SELECTEDVALUE(Produits[PRO_CODE]) = CurrentProduct
)
)
RETURN My_Sum

BBF

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.