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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
BN_04
Frequent Visitor

Previous datetime for streaming dataset

Hi,
I have streaming dataset. Requirement is to show live data. To perfrom some calculations I connect this dataset to powerbi Desktop and adding measures as per need. Now I am trying to create a measure which will give me perivous value of datetime. I want time diffrence of two entity. Please check below image.

BN_04_0-1696577493214.png

In this case I want new column with perivous datetime. I want to calculate time diffrence of non Blank ESN value to next stopper_down_time_Stamp.

I tried one measure-

 

CALCULATE(index(-2,ALLSELECTED('live-table'[HosurDateTime]),ORDERBY('live-table'[HosurDateTime],ASC)),KEEPFILTERS('live-table'))

But this is giving me only one value for latest record. not complete column values.

Please help me out.

Thanks.

1 ACCEPTED SOLUTION
Dangar332
Super User
Super User

Hi, @BN_04 

Use offset function instead of index function

Because Index only give static value and offset give daynamic value.

 

add column which give you previous value

pre = OFFSET(-1,ALLSELECTED(previous[datetime]),ORDERBY(previous[datetime],ASC))
here you can change (-1 to -2) if you want previous value of same id i take only previous value without same id
Dangar332_0-1696618402885.png

 

create mesure of difference bw two dates

diffinminutes =IF(VALUES(previous[pre])=BLANK(),0,DATEDIFF(max(previous[pre]),max(previous[datetime]),MINUTE))

here you can calculate difference as second, hour,day as your prefrence only replace minute to(second, hour,day) 
Dangar332_1-1696618603172.png
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly. Appreciate your kudos

 

View solution in original post

1 REPLY 1
Dangar332
Super User
Super User

Hi, @BN_04 

Use offset function instead of index function

Because Index only give static value and offset give daynamic value.

 

add column which give you previous value

pre = OFFSET(-1,ALLSELECTED(previous[datetime]),ORDERBY(previous[datetime],ASC))
here you can change (-1 to -2) if you want previous value of same id i take only previous value without same id
Dangar332_0-1696618402885.png

 

create mesure of difference bw two dates

diffinminutes =IF(VALUES(previous[pre])=BLANK(),0,DATEDIFF(max(previous[pre]),max(previous[datetime]),MINUTE))

here you can calculate difference as second, hour,day as your prefrence only replace minute to(second, hour,day) 
Dangar332_1-1696618603172.png
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly. Appreciate your kudos

 

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.