Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
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.
Solved! Go to Solution.
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:
Best Regards,
Lin
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:
Best Regards,
Lin
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.
Can someone please help?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
144 | |
75 | |
63 | |
51 | |
48 |
User | Count |
---|---|
211 | |
86 | |
64 | |
59 | |
56 |