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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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