Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Counting days for a given value without considering previous value

Hi, I will try to simplify at most to undermine understanding. I have a range of dates, for example from January 1st to March 1st. I have a table with a DATA column and another X column with a val...
  • v-easonf-msft's avatar
    v-easonf-msft
    5 years ago

    Hi, Anonymous 
    You need to create a index column in query editor first

    Then you can try  to create calculated columns as below:

    color flag = 
    VAR value1 =
        'COVID'[TRANSMISSIBILIDADE]
    RETURN
        SWITCH (
            TRUE (),
            value1 > 1.5, "red",
            value1 >= 1
                && value1 <= 1.5, "orange",
            value1 < 1, "green"
        )
    ChangedStatue = 
    VAR pre =
        CALCULATE (
            VALUES ( COVID[color flag] ),
            FILTER ( ALL ( COVID ), 'COVID'[Index] = EARLIER ( COVID[Index] ) - 1 )
        )
    RETURN
        IF ( ISBLANK ( pre ) || pre = 'COVID'[color flag],"unchanged","changed" )
    Counting days = 
    VAR _max =
        CALCULATE (
            MAX ( 'COVID'[Index] ),
            FILTER (
                'COVID',
                'COVID'[Index] <= EARLIER ( 'COVID'[Index] )
                    && 'COVID'[ChangedStatue] = "changed"
            )
        )
    RETURN
        IF ( ISBLANK ( _max ), 'COVID'[Index], 'COVID'[Index] - _max + 1 )

    The result will show as below:

     

    For more details,please check the attached file.

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.