Forum Discussion

xjsuarexcx's avatar
xjsuarexcx
Regular Visitor
3 years ago
Solved

counting consecutive identical values - calculated column

Dear ones, I need your support, thank you very much! I want to list (in the "Consecutive Imbalance" column) consecutive records that have a value equal to 1 (from the "Imbalance" column)...
  • v-yanjiang-msft's avatar
    3 years ago

    Hi xjsuarexcx ,

    If you need a calculated column, here's my solution.

    Create two calculated columns.

    Flag =
    MAXX (
        FILTER (
            'Query1',
            'Query1'[Timestamp] <= EARLIER ( 'Query1'[Timestamp] )
                && 'Query1'[Desbalance] = 0
        ),
        'Query1'[Timestamp]
    )
    
    Consecutive Imbalance =
    IF (
        'Query1'[Desbalance] = 1,
        RANKX (
            FILTER (
                'Query1',
                'Query1'[Desbalance] = 1
                    && 'Query1'[Flag] = EARLIER ( 'Query1'[Flag] )
            ),
            'Query1'[Timestamp],
            ,
            ASC
        )
    )
    

    Get the correct result.

    I attach my sample below for your reference.

     

    Best Regards,
    Community Support Team _ kalyj

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