Forum Discussion

VilmarSch's avatar
VilmarSch
Icon for Post Partisan rankPost Partisan
2 years ago
Solved

A Measure That Resets When It Encounters Zero Again

A measure that resets when it encounters zero again. _Measure2?   TAX_YEARWEEK _WeekNum _Measure1 _Measure2 202301 1 1 1 202301 2 1 2 202301 3 1 3 202301 4 1 4 202...
  • Anonymous's avatar
    Anonymous
    2 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_ Scott

     

    If this post helps then please consider Accept it as the solution to help the other members find it more quickly.