Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

counting consecutive identical values - calculated column

Hello master minds ,

I have a Power BI data set with TimeStamps.
Each are 15 minutes apart.
I would like to create a column that counts the number of consecutive timestamps with the same StatecategoryName.

This is an Excel sample of my data.
The results I want to calculate are in the last column "Consecutive Identical Values".


Thanks in advance
Bo

TimeStampLocal StateCategoryNameIndexConsecutive identical values
03-10-202100:00Downtime02
03-10-202100:15Downtime11
03-10-202100:30Uptime21
03-10-202100:45Downtime32
03-10-202101:00Downtime41
03-10-202101:15Uptime55
03-10-202101:30Uptime64
03-10-202101:45Uptime73
03-10-202102:00Uptime82
03-10-202102:15Uptime91
03-10-202102:30Downtime1016
03-10-202102:45Downtime1115
03-10-202103:00Downtime1214
03-10-202103:15Downtime1313
03-10-202103:30Downtime1412
03-10-202103:45Downtime1511
03-10-202104:00Downtime1610
03-10-202104:15Downtime179
03-10-202104:30Downtime188
03-10-202104:45Downtime197
03-10-202105:00Downtime206
03-10-202105:15Downtime215
03-10-202105:30Downtime224
03-10-202105:45Downtime233
03-10-202106:00Downtime242
03-10-202106:15Downtime251
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous ,

     

    Based on your description, you can create some columns as follows.

    Mark = 

    var x1=MAXX(FILTER('Consecutive',[Index]=EARLIER([Index])-1),[StateCategoryName])

    var x2=IF([StateCategoryName]=x1,0,1)

    return

    x2
    Category = SUMX(FILTER(ALL('Consecutive'),[Index]<=EARLIER('Consecutive'[Index])),[Mark])
    Consecutive_Test = RANKX(FILTER(ALL('Consecutive'),[Category]=EARLIER(Consecutive[Category])),[Index],,DESC)

    Result:

    Hope that's what you were looking for.

    Best Regards,

    Yuna

     

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

5 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks - I'll test it later today and let you know if it worked.

      Bo

  • Anonymous's avatar
    Anonymous
    Not applicable

    It is very nice and very close to what I am looking for, but I have trouble nailing the last bit.

     

    I replaced the 'Table1[Date] with my 'index'-columm as date-level is too coarse.

    The result is the accumulative sum for the period in question.

    It does not reset each time the statecategory changes.

     

    Probably I need to add another condition but am not sure how and which.

    Here is example with the results from the new column:

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Based on your description, you can create some columns as follows.

    Mark = 

    var x1=MAXX(FILTER('Consecutive',[Index]=EARLIER([Index])-1),[StateCategoryName])

    var x2=IF([StateCategoryName]=x1,0,1)

    return

    x2
    Category = SUMX(FILTER(ALL('Consecutive'),[Index]<=EARLIER('Consecutive'[Index])),[Mark])
    Consecutive_Test = RANKX(FILTER(ALL('Consecutive'),[Category]=EARLIER(Consecutive[Category])),[Index],,DESC)

    Result:

    Hope that's what you were looking for.

    Best Regards,

    Yuna

     

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      thank you very much - just what I was looking for!