The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hello,
I have a report that uses multiple cumulative totals by Year-to-Date month. The formula I've been using over and over is this:
YTDSumAdjUnadj =
VAR DateMaxYTD =
MAX ( 'FactTable'[YTDMonthNumber] )
RETURN
SUMX (
CALCULATETABLE (
'FactTable',
REMOVEFILTERS ( 'FactTable' ),
VALUES ( 'FactTable'[UserId] ),
'FactTable'[YTDMonthNumber] <= DateMaxYTD && 'FactTable'[YTDMonthNumber]>=1
),
[UnadjInclusiveSum]
)
Where [UserId] connects to my User Key table, and [YTDMonthNumber] just assigns 1 for Jan, 2 for Feb, etc.
This formula has worked for every measure I've used so far, except this one:
YTDRecovery =
VAR DateMaxYTD =
MAX ( 'FactTable'[YTDMonthNumber] )
RETURN
SUMX (
CALCULATETABLE (
'FactTable',
REMOVEFILTERS ( 'FactTable' ),
VALUES ( 'FactTable'[UserId] ),
'FactTable'[YTDMonthNumber] <= DateMaxYTD && 'FactTable'[YTDMonthNumber]>=1
),
[Recovery]
)
Where recovery is built like this:
Recovery = calculate([Unadjusted],filter(FactTable, FactTable[Recovery]=true))
Unadjusted = sum('FactTable'[UnadjustedK])
Where UnadjusedK is just a calculated column of values.
For some reason, Recovery is the only measure where that formula does not create a cumulative sum:
Hi @Brotedo ,
The problem is the CALCULATE() in [YTDRecovery].
CALCULATE will modify filter context, it means when you evaluate the [Recovery] in [YTDRecovery], it will ignore the filter you defined before.
So, you need add the filter "FactTable[Recovery]=True" to the CALCULATETABLE().
Maybe you can try this code:
YTDRecovery =
VAR DateMaxYTD =
MAX ( 'FactTable'[YTDMonthNumber] )
RETURN
SUMX (
CALCULATETABLE (
'FactTable',
REMOVEFILTERS ( 'FactTable' ),
VALUES ( 'FactTable'[UserId] ),
'FactTable'[YTDMonthNumber] <= DateMaxYTD
&& 'FactTable'[YTDMonthNumber] >= 1,
FILTER ( FactTable, FactTable[Recovery] = TRUE )
),
[Recovery]
)
Best regards.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Brotedo
If your model is a one-fact-table model (as it looks to be), I'd kindly suggest you change it to a proper star schema as quickly as you can before you are not able to explain what the model calculates. Seriously. One-table models inevitably lead to errors that you won't even be aware of and numbers you won't be able to explain.
User | Count |
---|---|
15 | |
13 | |
8 | |
6 | |
6 |
User | Count |
---|---|
24 | |
19 | |
12 | |
9 | |
7 |