Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
I already have the data sorted and indexed. Is there a way to do the cummulative sum using DAX for the set of row that have the state set to True?
Something like this:
Any help is greatly appreciated!
Note:
1. The data doens't have data field that's why I created the index field for the cummulative sum and getting the previous state value on BI.
2. I saw an example of this being done using m-code but my dataset is too big to incorporate that. The powerQuery never loaded and crashed the report. 😞 And for some reason I get better performance writing DAX than having the caculations done on powerQuery.
Solved! Go to Solution.
Please try this column expression.
CumulativeIndex =
VAR vThisIndex = State[Index]
VAR vLastFalse =
CALCULATE (
MAX ( State[Index] ),
State[State]
= FALSE (),
State[Index] <= vThisIndex
)
VAR vSum =
CALCULATE (
SUM ( State[Index] ),
State[Index] <= vThisIndex,
State[Index] > vLastFalse
)
RETURN
IF (
State[State]
= TRUE (),
vSum
)
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
You need to add ALL(Sample_Data) to the CALCULATE in both vLastFalse and vSum to account for the effects of context transition
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Thank you @AlB @mahoneypat
For anyone looking for a solution to a similar problem, here's the DAX formula after implementing ALL(Sample_data) suggested by
CumulativeIndex =
VAR vThisIndex = Sample_data[Index]
VAR vLastFalse =
CALCULATE (
MAX (Sample_data[Index] ),ALL(Sample_data),
Sample_data[State]
= FALSE (),
Sample_data[Index] <= vThisIndex
)
VAR vSum =
CALCULATE (
SUM ( Sample_data[Data]),ALL(Sample_data),
Sample_data[Index] <= vThisIndex,
Sample_data[Index] > vLastFalse
)
RETURN
IF (
Sample_data[State]
= TRUE (),
vSum
)
You need to add ALL(Sample_Data) to the CALCULATE in both vLastFalse and vSum to account for the effects of context transition
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Please try this column expression.
CumulativeIndex =
VAR vThisIndex = State[Index]
VAR vLastFalse =
CALCULATE (
MAX ( State[Index] ),
State[State]
= FALSE (),
State[Index] <= vThisIndex
)
VAR vSum =
CALCULATE (
SUM ( State[Index] ),
State[Index] <= vThisIndex,
State[Index] > vLastFalse
)
RETURN
IF (
State[State]
= TRUE (),
vSum
)
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
I modified the code a little bit to sum of the Data field instead of the index on line 12. But it doesn't look like it's doing the cummulative sum. Looks like it's just showing the data from the data field.
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
31 | |
16 | |
12 | |
10 | |
8 |
User | Count |
---|---|
59 | |
20 | |
12 | |
11 | |
10 |