Forum Discussion
A Measure That Resets When It Encounters Zero Again
- Anonymous2 years ago
Hi VilmarSch,
Based on your description, I performed a grouping operation through the _WeekNum column, using Measure1 as the cumulative value, and you may check the following results:
It's roughly in three parts, I modeled your Measure1 by value, then judged Measure1 and grouped it using _Weeknum as an identifier, and finally calculated the sum for each group
DAX for measure:
Rank by Group = VAR _STEP1 = SUMMARIZE ( ALLSELECTED ( 'Table' ), 'Table'[TAX_YEARWEEK], 'Table'[_WeekNum], "Measure1", CALCULATE ( SUM ( 'Table'[Value] ) ) ) VAR _STEP2 = ADDCOLUMNS ( _STEP1, "First equal to 0", IF ( [Measure1] = 0, BLANK (), MINX ( FILTER ( _STEP1, [Measure1] = 0 && [_WeekNum] > EARLIER ( [_WeekNum] ) ), [_WeekNum] ) ) ) VAR _STEP3 = ADDCOLUMNS ( _STEP2, "Running Total", SUMX ( FILTER ( _STEP2, [First equal to 0] = EARLIER ( [First equal to 0] ) && [_WeekNum] <= EARLIER ( [_WeekNum] ) && [Measure1] <> 0 ), [Measure1] ) ) RETURN SUMX ( FILTER ( _STEP3, [TAX_YEARWEEK] = MAX ( 'Table'[TAX_YEARWEEK] ) && [_WeekNum] = MAX ( 'Table'[_WeekNum] ) ), [Running Total] )An attachment for your reference. Hope it helps!
Best regards,
Community Support Team_ ScottIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi VilmarSch,
Based on your description, I performed a grouping operation through the _WeekNum column, using Measure1 as the cumulative value, and you may check the following results:
It's roughly in three parts, I modeled your Measure1 by value, then judged Measure1 and grouped it using _Weeknum as an identifier, and finally calculated the sum for each group
DAX for measure:
Rank by Group =
VAR _STEP1 =
SUMMARIZE (
ALLSELECTED ( 'Table' ),
'Table'[TAX_YEARWEEK],
'Table'[_WeekNum],
"Measure1", CALCULATE ( SUM ( 'Table'[Value] ) )
)
VAR _STEP2 =
ADDCOLUMNS (
_STEP1,
"First equal to 0",
IF (
[Measure1] = 0,
BLANK (),
MINX (
FILTER ( _STEP1, [Measure1] = 0 && [_WeekNum] > EARLIER ( [_WeekNum] ) ),
[_WeekNum]
)
)
)
VAR _STEP3 =
ADDCOLUMNS (
_STEP2,
"Running Total",
SUMX (
FILTER (
_STEP2,
[First equal to 0] = EARLIER ( [First equal to 0] )
&& [_WeekNum] <= EARLIER ( [_WeekNum] )
&& [Measure1] <> 0
),
[Measure1]
)
)
RETURN
SUMX (
FILTER (
_STEP3,
[TAX_YEARWEEK] = MAX ( 'Table'[TAX_YEARWEEK] )
&& [_WeekNum] = MAX ( 'Table'[_WeekNum] )
),
[Running Total]
)
An attachment for your reference. Hope it helps!
Best regards,
Community Support Team_ Scott
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.