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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calculate column base on two rows in same timestamp

Hi i want to create a new column base on category F and G value, it need to be check for every timestamp, when F and G is over the Alarm it will be 1 otherwise 0. 

timeCategogyAlarmTemp
2021-12-14 07:01A208.08
2021-12-14 07:01B209.27
2021-12-14 07:01C206.67
2021-12-14 07:01D204.93
2021-12-14 07:01E204.07
2021-12-14 07:01F8083.57
2021-12-14 07:01G100103.4
2021-12-14 07:02A208.09
2021-12-14 07:02B209.28
2021-12-14 07:02C206.67
2021-12-14 07:02D204.94
2021-12-14 07:02E204.07
2021-12-14 07:02F8083.74
2021-12-14 07:02G100103.09
2021-12-14 07:03A208.11
2021-12-14 07:03B209.3
2021-12-14 07:03C206.68
2021-12-14 07:03D204.96
2021-12-14 07:03E204.07
2021-12-14 07:03F8084.07
2021-12-14 07:03G100102.58
1 ACCEPTED SOLUTION

@Anonymous 

you can try this

Column = 
VAR _nextalarm=maxx(FILTER('Table','Table'[Category]="G"&&'Table'[time]=EARLIER('Table'[time])),'Table'[Alarm])
VAR _nexttemp=maxx(FILTER('Table','Table'[Category]="G"&&'Table'[time]=EARLIER('Table'[time])),'Table'[Temp])
VAR _lastalarm=maxx(FILTER('Table','Table'[Category]="F"&&'Table'[time]=EARLIER('Table'[time])),'Table'[Alarm])
VAR _lasttemp=maxx(FILTER('Table','Table'[Category]="F"&&'Table'[time]=EARLIER('Table'[time])),'Table'[temp])
RETURN IF('Table'[Category]="F"&&'Table'[Temp]>'Table'[Alarm]&&_nexttemp>_nextalarm,1,if('Table'[Category]="G"&&'Table'[Temp]>'Table'[Alarm]&&_lasttemp>_lastalarm,1,0))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , what do mean by "when F and G is over the Alarm"

 

Can you share expected output

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Yes like this:

timeCategoryAlarmTempoutput
2021-12-14 07:01A208.080
2021-12-14 07:01B209.270
2021-12-14 07:01C206.670
2021-12-14 07:01D204.930
2021-12-14 07:01E204.070
2021-12-14 07:01F8083.571
2021-12-14 07:01G100103.41
2021-12-14 07:02A208.090
2021-12-14 07:02B209.280
2021-12-14 07:02C206.670
2021-12-14 07:02D204.950
2021-12-14 07:02E204.070
2021-12-14 07:02F8083.741
2021-12-14 07:02G100103.091
2021-12-14 07:03A208.110
2021-12-14 07:03B209.30
2021-12-14 07:03C206.680
2021-12-14 07:03D204.960
2021-12-14 07:03E204.070
2021-12-14 07:03F8074.070
2021-12-14 07:03G100102.580

 

if it in same timestamp and categoy G is over the alarm and category f is over the alarm then 1 
if categoy G is over the alarm but not category f then 0 , both G and F need to be over the Alarm value to set it 1. 

@Anonymous 

you can try this

Column = 
VAR _nextalarm=maxx(FILTER('Table','Table'[Category]="G"&&'Table'[time]=EARLIER('Table'[time])),'Table'[Alarm])
VAR _nexttemp=maxx(FILTER('Table','Table'[Category]="G"&&'Table'[time]=EARLIER('Table'[time])),'Table'[Temp])
VAR _lastalarm=maxx(FILTER('Table','Table'[Category]="F"&&'Table'[time]=EARLIER('Table'[time])),'Table'[Alarm])
VAR _lasttemp=maxx(FILTER('Table','Table'[Category]="F"&&'Table'[time]=EARLIER('Table'[time])),'Table'[temp])
RETURN IF('Table'[Category]="F"&&'Table'[Temp]>'Table'[Alarm]&&_nexttemp>_nextalarm,1,if('Table'[Category]="G"&&'Table'[Temp]>'Table'[Alarm]&&_lasttemp>_lastalarm,1,0))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors