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

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

Reply
Anonymous
Not applicable

Increment variable after condition

Hi Guys,

 

I need a help with the case below:

How to write it in Dax or Powerquery a code like this below:

 

Expected Result =

VAR V_ID = 1
RETURN

    if('Table'[OverflowAlarm] = 1 && 'Table'[Previus row] = 0, V_ID, 
        if('Table'[OverflowAlarm] = 0 && 'Table'[Previus row] = 1,    V_ID = V_ID +1 ,

           if ('Table'[OverflowAlarm] = 1 && 'Table'[Previus row] = 1, 'Table'[OverflowAlarm],0
)))

 

I have a table like that:

Time/datePoint_IdIndexDurationOverflowAlarmPrevius row
14/03/2018 23:45PDD1114878241151 
14/03/2018 23:30PDD11148782421511
14/03/2018 23:15PDD11148782431511
14/03/2018 23:00PDD11148782441511
14/03/2018 22:45PDD11148782451511
14/03/2018 22:30PDD11148782461510
14/03/2018 22:15PDD1114878247000
14/03/2018 22:00PDD1114878248000
14/03/2018 21:45PDD1114878249000
14/03/2018 21:30PDD1114878250000
14/03/2018 21:15PDD1114878251000
14/03/2018 21:00PDD1114878252000
14/03/2018 20:45PDD1114878253001
14/03/2018 20:30PDD11148782541510
14/03/2018 20:15PDD1114878255001
14/03/2018 20:00PDD11148782561511
14/03/2018 19:45PDD11148782571511
14/03/2018 19:30PDD11148782581511
14/03/2018 19:15PDD11148782591511
14/03/2018 19:00PDD11148782601511

 

And that is the result that I need:

 

Point_IdIndexDurationOverflowAlarmPrevius rowExpected Result
PDD1114878241151 event 1
PDD11148782421511event 1
PDD11148782431511event 1
PDD11148782441511event 1
PDD11148782451511event 1
PDD11148782461510event 1
PDD1114878247000 
PDD1114878248000 
PDD1114878249000 
PDD1114878250000 
PDD1114878251000 
PDD1114878252000 
PDD1114878253001 
PDD11148782541510event 2
PDD1114878255001 
PDD11148782561511event 3
PDD11148782571511event 3
PDD11148782581511event 3
PDD11148782591511event 3
PDD11148782601511

event 3

 

Any help is welcome!

Thanks

3 REPLIES 3
dqdqwqdwwdqwqwd
New Member

They've surrounded us. thanks for all you have done

v-chuncz-msft
Community Support
Community Support

@Anonymous ,

 

You may take a look at the post below.

https://community.powerbi.com/t5/Desktop/Finding-the-previos-occurrence-within-same-table-based-on-one/m-p/342607#M153516

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi,

 


@v-chuncz-msft wrote:

@Anonymous ,

 

You may take a look at the post below.

https://community.powerbi.com/t5/Desktop/Finding-the-previos-occurrence-within-same-table-based-on-one/m-p/342607#M153516



Thanks for your response.

I am not a Power Bi expert, I've been working only few weeks with it. But, I couldn't see it working for me. And the function earlier doesn't work well... too many rows in the table, it runs forever... Any other solution?

 

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.