Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BST
Frequent Visitor

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
1 ACCEPTED SOLUTION
v-yuaj-msft
Community Support
Community Support

Hi @BST ,

 

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:

v-yuaj-msft_0-1616742433170.png

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.

View solution in original post

5 REPLIES 5
v-yuaj-msft
Community Support
Community Support

Hi @BST ,

 

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:

v-yuaj-msft_0-1616742433170.png

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.

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

BST
Frequent Visitor

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:

BST_0-1616609369011.png

 

amitchandak
Super User
Super User

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

Bo

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.