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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Krankyboy
New Member

Looping through a table to find a vaue

Hi 

 

I want to pass into a function a date and number, (the number of workdays a task will take) from my fact table.  I have a second table which is  just rows of workdays and a second column with a value of 1 - this signifies that the associated date is a workday.  Any dates falling on a weekend or stat holiday have been removed.

 

Basically I want to loop N times through the table and return the date.

 

Thanks,

 

A

5 REPLIES 5
Anonymous
Not applicable

Hi @Krankyboy ,

 

Please try new a custom function:

let
    GetEndDate = (startDate as date, workDays as number) =>
        let
            filteredWorkDays = Table.SelectRows(Table, each [date] >= startDate),
            workDayList = List.Distinct(Table.Column(filteredWorkDays, "date")),
            requiredWorkDays = List.FirstN(workDayList, workDays),
            endDate = List.Last(requiredWorkDays)
        in
            endDate
in
    GetEndDate

vcgaomsft_0-1732070647395.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Omid_Motamedise
Super User
Super User

I didnt catch your question but for applying loop, this video can be helpful

https://youtu.be/G8PRbWuDcmQ

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
slorin
Super User
Super User

Hi @Krankyboy 

 

Workdays_Table[Workday_Column]{List.PositionOf(Workdays_Table[Workday_Column], [date]) + [number] }
 

Stéphane

Hi,

 

Thanks for the response.  But this is not the answer.  I should have added more info.

 

my workday table is just rows like the following;

date                 isWorkDay (always 1)

2025-01-02    1

2025-01-03    1

2025-01-06    1

2024-01-07    1

 

I want to pass in a task start date, say 2025-01-01 which takes 3 days,  I assume I would have to loop 3 times then return 2025-01-06.   That returned date will become the start date for the next task.  My fact table will have about 12 task starts per row along with 12 workdays.

=Table.ExpandListColumn(Table.AddColumn(YourFactTable,"Workday Date",each List.FirstN(Table.Skip(WorkdayTable,(x)=>x[Date]<[Date])[Date],[Number])),"Workday Date")

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors