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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
DanielV91
Frequent Visitor

Calculated column based on rows position

Capture.JPG

Having the above table where delta is the difference between curent timestamp and previous one, I want to calculate the column for the far right. Which function should I use, or how can I approach this? Doesn't matter if it is DAX or Power M query.

Thanks!

1 ACCEPTED SOLUTION
alexei7
Continued Contributor
Continued Contributor

Ah yeah, sorry.

 

Try it with an equals sign as well as the "<":

 

Column = "Observation "&CALCULATE(COUNTROWS(Table1),ALLEXCEPT(Table1,Table1[id]),Table1[timestamp]<=EARLIER(Table1[timestamp]),Table1[delta]>2)+1

 

Alex

View solution in original post

6 REPLIES 6
v-juanli-msft
Community Support
Community Support

Hi @DanielV91

Try this formula

calculated column =
IF ( [delta] > 2, "Observation2", "Observation1" )

 

Best Regards

Maggie 

Thanks for replying but that formula will not work. I will end up having "Observation 1" for everything except the rows where delta is greater than 2.
The observations need to be incremented when delta greater than 2 is found for the same ID while going down the table. Also, when the ID changes, observations need to start again / reset.

 

My programing logic is like this:

 

  1. For all IDs 
    1. declare a counter = 1 
    2. For all rows 
      • IF (delta <= 2 OR delta = NULL) { "Observation " + counter' }
      • ELSE { counter +1; "Observation " + counter; }
    3. reset counter to 1
alexei7
Continued Contributor
Continued Contributor

Hi Daniel,

 

I think the following calculated column will do the job for you.

 

Can you try it and let me know how you get on (obviously replacing table and column names with your own):

 

Column = "Observation "&CALCULATE(COUNTROWS(Table1),ALLEXCEPT(Table1,Table1[id]),Table1[timestamp]<EARLIER(Table1[timestamp]),Table1[delta]>2)+1

Hope that helps,

Alex

cap.JPG

 

@alexei7 thanks for replying! It is very close, but the ones where delta is greater than 2 should have asigned the next number. 
Basically for the ones that I marked with red should be '2'.

alexei7
Continued Contributor
Continued Contributor

Ah yeah, sorry.

 

Try it with an equals sign as well as the "<":

 

Column = "Observation "&CALCULATE(COUNTROWS(Table1),ALLEXCEPT(Table1,Table1[id]),Table1[timestamp]<=EARLIER(Table1[timestamp]),Table1[delta]>2)+1

 

Alex

@alexei7 Thank you! Works now.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors