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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
goncalogeraldes
Super User
Super User

Running total is reversed

Hello there! I have a running total formula that is performing in the opposite way as expected (needed). I have tried changing it in many ways but it either doesn't make sense or just gives zeros. Right now the output and the formula are as follow:

 

 

 

Running Total %  = 

var rankcheck = RANKX ( ALL ( 'ds05 - Vendas'[Cliente] ), [Valor2],, ASC )
var runningTotal = CALCULATE( [Valor2], FILTER( ALL( 'ds05 - Vendas'[Cliente] ), RANKX ( ALL ( 'ds05 - Vendas'[Cliente] ), [Valor2], , ASC ) <= rankcheck ))
var totalSales = CALCULATE( [Valor2], ALL( 'ds05 - Vendas'[Cliente] ))

return 
DIVIDE(runningTotal,totalSales,0)

 

 

 

goncalogeraldes_0-1631022740839.png

 

The expected result is:

Column1Column2Column3
619,4221,89%21,89%
588,5020,80%42,69%
287,1010,15%52,84%

 

Thanks in advance for any kind of help!

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @goncalogeraldes 

 

Have you tried changing the sorting order on the rankx?

Running Total % =
VAR rankcheck =
    RANKX ( ALL ( 'ds05 - Vendas'[Cliente] ), [Valor2],, DESC )
VAR runningTotal =
    CALCULATE (
        [Valor2],
        FILTER (
            ALL ( 'ds05 - Vendas'[Cliente] ),
            RANKX ( ALL ( 'ds05 - Vendas'[Cliente] ), [Valor2],, DESC ) <= rankcheck
        )
    )
VAR totalSales =
    CALCULATE ( [Valor2], ALL ( 'ds05 - Vendas'[Cliente] ) )
RETURN
    DIVIDE ( runningTotal, totalSales, 0 )

 

If this does not work can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @goncalogeraldes 

 

Have you tried changing the sorting order on the rankx?

Running Total % =
VAR rankcheck =
    RANKX ( ALL ( 'ds05 - Vendas'[Cliente] ), [Valor2],, DESC )
VAR runningTotal =
    CALCULATE (
        [Valor2],
        FILTER (
            ALL ( 'ds05 - Vendas'[Cliente] ),
            RANKX ( ALL ( 'ds05 - Vendas'[Cliente] ), [Valor2],, DESC ) <= rankcheck
        )
    )
VAR totalSales =
    CALCULATE ( [Valor2], ALL ( 'ds05 - Vendas'[Cliente] ) )
RETURN
    DIVIDE ( runningTotal, totalSales, 0 )

 

If this does not work can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelix I have and it never worked until now so I guess it must have been some filter context had in place which has since been deleted! Thanks for your help!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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