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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
marcelojunior88
Regular Visitor

How to accumulate negative values ​​in a measurement using rankx?

I am performing a calculation where the values ​​are being accumulated according to the ranking position (from the highest value, to the lowest), using rankx for this.
However when there are negative values, it is not adding to the calculation.
Does anyone know how to fix it?
Below, the code I'm doing:

_SomaValorReal = SUM(fRealizado[Valor]) -- MEASURE1

 

_RankingGeralReal = RANKX(ALLSELECTED(dCentroDeCustoDW),[_SomaValorReal]) -- MEASURE2

 

_AcumuladoReal =
var contextoR = [_RankingGeralReal]
var fatacumR =
CALCULATE(
[_SomaValorReal],
FILTER(
ALL(dCentroDeCustoDW),
[_RankingGeralReal] <= contextoR
)
)
RETURN
fatacumR

 

And in the image below, the (wrong) form that the calculation returns:

 

marcelojunior88_0-1702901972929.png

 

1 ACCEPTED SOLUTION
some_bih
Super User
Super User

Hi @marcelojunior88 

in third measure "_AcumuladoReal " there is reference to second measure _RankingGeralReal which use ALLSELECTED funtion. 

When one measure call another measure with ALLSELECTED, then results are almost impossible to understand / spot cause for unlogical amounts. The best practice for ALLSELECTED is to use it for single visual, not chain measure with ALLSELECTED to another measure.

You will need to rework your measure.

One possible solution could be that you create VAR in third measure with definition of second measure. So test this approach and see results.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






View solution in original post

2 REPLIES 2
marcelojunior88
Regular Visitor

Thank you very much,
I replaced "allselected" by "all", and in the context of what I wanted, it worked

 

some_bih
Super User
Super User

Hi @marcelojunior88 

in third measure "_AcumuladoReal " there is reference to second measure _RankingGeralReal which use ALLSELECTED funtion. 

When one measure call another measure with ALLSELECTED, then results are almost impossible to understand / spot cause for unlogical amounts. The best practice for ALLSELECTED is to use it for single visual, not chain measure with ALLSELECTED to another measure.

You will need to rework your measure.

One possible solution could be that you create VAR in third measure with definition of second measure. So test this approach and see results.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.