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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jesuslogmein
Helper I
Helper I

Loop in PowerBI PQuery

I am trying to make a for loop in power query but I am unable to.
I need to create a new column that accumulates +1 if for the same employee and successive dates and situation="abs" increments its value by 1 otherwise it would have to restart at 0.

I have tried List.Generate, but I don't know how to implement it in a column.

jesuslogmein_0-1682606988313.png

jesuslogmein_1-1682607112165.png

 

 

1 REPLY 1
wdx223_Daniel
Super User
Super User

it's hard to do this with Table.AddColumn, suggest you to add a new step with this code

NewStep=Table.FromRecords(List.Accumulate(Table.ToRecords(PreviousStepName),{{},"",0,0},(x,y)=>if y[Empoyee]=x{1} and y[Situation]="ABS" and y[Date]=Date.AddDates(x{2},1) then {x{0}&{y&[LD=x{3}+1]},y[Employee],y[Date],x{3}+1} else {x{0}&{y&[LD=Byte.From(y[Situation]="ABS")]},y[Employee],y[Date],Byte.From(y[Situation]="ABS")}){0})

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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