cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jgoncal Frequent Visitor
Frequent Visitor

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

2 REPLIES 2
Community Support Team
Community Support Team

Re: Increment variable after condition

@jgoncal ,

 

You may take a look at the post below.

https://community.powerbi.com/t5/Desktop/Finding-the-previos-occurrence-within-same-table-based-on-o...

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.
jgoncal Frequent Visitor
Frequent Visitor

Re: Increment variable after condition

Hi,

 


@v-chuncz-msft wrote:

@jgoncal ,

 

You may take a look at the post below.

https://community.powerbi.com/t5/Desktop/Finding-the-previos-occurrence-within-same-table-based-on-o...



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
New Kudos Received Badges Coming

New Kudos Received Badges Coming

Kudos to you if you earned one of these! Check your inbox for a notification.

Microsoft Implementation for Communities Wins Award

Microsoft Implementation for Communities Wins Award

Learn about the award-winning innovation that was implemented across Microsoft’s Business Applications Communities.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Kudoed Authors (Last 30 Days)
Users online (2,789)