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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
sqlguru448
Helper III
Helper III

Running Total in DAX Analysis Services issue

Hello,

 

Can you please help me in the below DAX which I am trying to write in creating Running Total based off Index. I am trying to execute in Analysis services not in Power BI.

 

EVALUATE
 (
    VAR countsales =
        SUMMARIZECOLUMNS (
            'DimProductSubcategory'[EnglishProductSubcategoryName],
            "counter"SUMX (
                FactInternetSales,
                FactInternetSales[OrderQuantity] * FactInternetSales[UnitPrice]
            )
        )
    VAR FINAL =
        ADDCOLUMNS (
            countsales,
            "Indexz"RANKX ( countsales, DimProductSubcategory[EnglishProductSubcategoryName],, asc )
        ) //var trying = ADDCOLUMNS(FINAL, "Running Total", CALCULATE(SUMX(FINAL,[counter]), FILTER(ALL(final),[Indexz]<=[Indexz])))
    RETURN
        ADDCOLUMNS (
            FINAL,
            "Running Total"CALCULATE (
                SUMX ( final, [counter] ),
                FILTER ( final, [Indexz] <= EARLIER ( [Indexz] ) )
            )
        )
)
ORDER BY DimProductSubcategory[EnglishProductSubcategoryName]

 

Please help/guide me to correct above DAX in creating a valid running total.

 

Running_total_issue.PNG

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

HI, @sqlguru448

After my test, you could try this formula as below:

EVALUATE
 (
    VAR countsales =
        SUMMARIZECOLUMNS (
            'DimProductSubcategory'[EnglishProductSubcategoryName],
            "counter", SUMX (
                FactInternetSales,
                FactInternetSales[OrderQuantity] * FactInternetSales[UnitPrice]
            )
        )
    VAR FINAL =
        ADDCOLUMNS (
            countsales,
            "Indexz", RANKX ( countsales, DimProductSubcategory[EnglishProductSubcategoryName],, asc )
        ) //var trying = ADDCOLUMNS(FINAL, "Running Total", CALCULATE(SUMX(FINAL,[counter]), FILTER(ALL(final),[Indexz]<=[Indexz])))
    RETURN
        ADDCOLUMNS (
            FINAL,
            "Running Total",
            VAR currentIndex = [Indexz]
            RETURN
                SUMX ( FILTER ( FINAL, [Indexz] <= currentIndex ), [counter] )
        )
)
ORDER BY DimProductSubcategory[EnglishProductSubcategoryName]

Result:

4.JPG

 

Best Regards,

Lin

 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

HI, @sqlguru448

After my test, you could try this formula as below:

EVALUATE
 (
    VAR countsales =
        SUMMARIZECOLUMNS (
            'DimProductSubcategory'[EnglishProductSubcategoryName],
            "counter", SUMX (
                FactInternetSales,
                FactInternetSales[OrderQuantity] * FactInternetSales[UnitPrice]
            )
        )
    VAR FINAL =
        ADDCOLUMNS (
            countsales,
            "Indexz", RANKX ( countsales, DimProductSubcategory[EnglishProductSubcategoryName],, asc )
        ) //var trying = ADDCOLUMNS(FINAL, "Running Total", CALCULATE(SUMX(FINAL,[counter]), FILTER(ALL(final),[Indexz]<=[Indexz])))
    RETURN
        ADDCOLUMNS (
            FINAL,
            "Running Total",
            VAR currentIndex = [Indexz]
            RETURN
                SUMX ( FILTER ( FINAL, [Indexz] <= currentIndex ), [counter] )
        )
)
ORDER BY DimProductSubcategory[EnglishProductSubcategoryName]

Result:

4.JPG

 

Best Regards,

Lin

 

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Lin,

 

Can you please explain why my DAX was not working even though I was using EARLIER function? is this because of FILTER context being applied instead of row context?

 

 

 

Thank you very much for your quick response.

sqlguru448
Helper III
Helper III

Can someone please help?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 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.

Top Solution Authors
Top Kudoed Authors