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.
Hi There, Could anybody held with this Dax Query. I Group Sales by month and created a raking, as following:
DEFINE
VAR Sales =
ADDCOLUMNS (
VALUES ( 'DIM PRODUCTO'[PRODUCTO]),
"@SalesMonth", CALCULATE([VENTAS EN UNIDADES], 'DIM TIEMPO'[AÑO-MES]="2024-03")
)
EVALUATE
ADDCOLUMNS (
Sales,
"Rank",
RANKX (
Sales,
[@SalesMonth]
)
)
ORDER BY [@SalesMonth] DESC
This is the result:
Is there any way to do a running total based on this result?
Thanks
Solved! Go to Solution.
I noticed an error in the original query which I have corrected in my earlier post (a reference to SalesTable that should have been Sales).
In order to break ties as was suggested, one method for :
DEFINE
VAR Sales =
ADDCOLUMNS (
VALUES ( 'DIM PRODUCTO'[PRODUCTO] ),
"@SalesMonth",
CALCULATE (
[VENTAS EN UNIDADES],
'DIM TIEMPO'[AÑO-MES] = "2024-03"
)
)
EVALUATE
ADDCOLUMNS (
Sales,
"Rank",
RANKX (
Sales,
[@SalesMonth]
),
"RunningTotal",
SUMX (
WINDOW (
1,
ABS,
0,
REL,
Sales,
ORDERBY ( [@SalesMonth], DESC, 'DIM PRODUCTO'[PRODUCTO], ASC )
),
[@SalesMonth]
)
)
ORDER BY [@SalesMonth] DESC
If your DAX version doesn't have the WINDOW function, you could use:
DEFINE
VAR Sales =
ADDCOLUMNS (
VALUES ( 'DIM PRODUCTO'[PRODUCTO] ),
"@SalesMonth",
CALCULATE (
[VENTAS EN UNIDADES],
'DIM TIEMPO'[AÑO-MES] = "2024-03"
)
)
EVALUATE
ADDCOLUMNS (
Sales,
"Rank",
RANKX (
Sales,
[@SalesMonth]
),
"RunningTotal",
VAR CurrentSalesMonth = [@SalesMonth]
VAR CurrentProduct = 'DIM PRODUCTO'[PRODUCTO]
RETURN
SUMX (
FILTER (
Sales,
[@SalesMonth] > CurrentSalesMonth
|| [@SalesMonth] = CurrentSalesMonth && 'DIM PRODUCTO'[PRODUCTO] <= CurrentProduct
),
[@SalesMonth]
)
)
ORDER BY [@SalesMonth] DESC
I noticed an error in the original query which I have corrected in my earlier post (a reference to SalesTable that should have been Sales).
In order to break ties as was suggested, one method for :
DEFINE
VAR Sales =
ADDCOLUMNS (
VALUES ( 'DIM PRODUCTO'[PRODUCTO] ),
"@SalesMonth",
CALCULATE (
[VENTAS EN UNIDADES],
'DIM TIEMPO'[AÑO-MES] = "2024-03"
)
)
EVALUATE
ADDCOLUMNS (
Sales,
"Rank",
RANKX (
Sales,
[@SalesMonth]
),
"RunningTotal",
SUMX (
WINDOW (
1,
ABS,
0,
REL,
Sales,
ORDERBY ( [@SalesMonth], DESC, 'DIM PRODUCTO'[PRODUCTO], ASC )
),
[@SalesMonth]
)
)
ORDER BY [@SalesMonth] DESC
If your DAX version doesn't have the WINDOW function, you could use:
DEFINE
VAR Sales =
ADDCOLUMNS (
VALUES ( 'DIM PRODUCTO'[PRODUCTO] ),
"@SalesMonth",
CALCULATE (
[VENTAS EN UNIDADES],
'DIM TIEMPO'[AÑO-MES] = "2024-03"
)
)
EVALUATE
ADDCOLUMNS (
Sales,
"Rank",
RANKX (
Sales,
[@SalesMonth]
),
"RunningTotal",
VAR CurrentSalesMonth = [@SalesMonth]
VAR CurrentProduct = 'DIM PRODUCTO'[PRODUCTO]
RETURN
SUMX (
FILTER (
Sales,
[@SalesMonth] > CurrentSalesMonth
|| [@SalesMonth] = CurrentSalesMonth && 'DIM PRODUCTO'[PRODUCTO] <= CurrentProduct
),
[@SalesMonth]
)
)
ORDER BY [@SalesMonth] DESC
Hi Owen,
The second solution gets error timeout, but I deleted the line:
|| [@SalesMonth] = CurrentSalesMonth && 'DIM PRODUCTO'[PRODUCTO] <= CurrentProduct
and It worked perfectly.
Thank you very much.
Just for general knowledge. the WINDOWS function is not included in my DAX, is it a possible solution to update my SSAS version to a newer one?
Glad to hear it 🙂
I don't have specific experience on upgrading SSAS Tabular, but see here:
It appears that you need a recent build of SSAS 2022 for WINDOW and related functions.
Regards
The standard pattern is to sum up all values that are greater than or equal to the current value (like a Pareto). For ties you need to find a suitable tie breaker, for example the product name.
Hi, I tried to do it, but I'm kind of lost on this. I added an extra column in ADDCOLUMS like this:
"Sum",
CALCULATE(
sumx(
sales,
[@SalesMonth]
),
FILTER(
ALLSELECTED(sales),
[@SalesMonth] >= MAX([@SalesMonth])
)
)
but how do I put the suitable tie breaker here?
Thanks
If you want to add a running total to the table returned, you could use the WINDOW function. For example:
DEFINE
VAR Sales =
ADDCOLUMNS (
VALUES ( 'DIM PRODUCTO'[PRODUCTO] ),
"@SalesMonth",
CALCULATE (
[VENTAS EN UNIDADES],
'DIM TIEMPO'[AÑO-MES] = "2024-03"
)
)
EVALUATE
ADDCOLUMNS (
Sales,
"Rank",
RANKX (
Sales,
[@SalesMonth]
),
"RunningTotal",
SUMX (
WINDOW (
1,
ABS,
0,
REL,
Sales,
ORDERBY ( [@SalesMonth], DESC, 'DIM PRODUCTO'[PRODUCTO], ASC )
),
[@SalesMonth]
)
)
ORDER BY [@SalesMonth] DESC
Is this the sort of thing you were looking for?
Regards
Hi Owen, I tried your approach, but I get an error message:
Failed to resolve the name 'ABS'. It is not a valid table, variable or function name.
what do you think could be the issue?
Thanks
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 |
---|---|
18 | |
15 | |
14 | |
11 | |
8 |
User | Count |
---|---|
24 | |
19 | |
12 | |
11 | |
10 |