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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

how to dynamically retrieve previous working day ?

Hello,

This url gives me the french bank holidays : https://calendrier.api.gouv.fr/jours-feries/metropole.json

Can you tell me how to write a function that takes a date as a parameter and returns the previous working day from the date in paramater (so not a week-end, and not one of the bank holidays contained in the above json) please ?

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

You can use this function

= (InputDate)=>
let
    Source = Record.ToTable(Json.Document(Web.Contents("https://calendrier.api.gouv.fr/jours-feries/metropole.json"))),
    CalendarDates = List.Transform(Source[Name], each Date.From(_)),
    ListDates = List.Select(List.Dates(#date(1899,12,30), Duration.Days(Date.From(InputDate)-#date(1899,12,30)), #duration(1,0,0,0)), each Date.DayOfWeek(_,1)<5),
    PreviousWorkDay = List.Last(List.Difference(ListDates, CalendarDates))
in
    PreviousWorkDay

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

You can use this function

= (InputDate)=>
let
    Source = Record.ToTable(Json.Document(Web.Contents("https://calendrier.api.gouv.fr/jours-feries/metropole.json"))),
    CalendarDates = List.Transform(Source[Name], each Date.From(_)),
    ListDates = List.Select(List.Dates(#date(1899,12,30), Duration.Days(Date.From(InputDate)-#date(1899,12,30)), #duration(1,0,0,0)), each Date.DayOfWeek(_,1)<5),
    PreviousWorkDay = List.Last(List.Difference(ListDates, CalendarDates))
in
    PreviousWorkDay
Anonymous
Not applicable

Thank you !

I have a similar question here https://community.powerbi.com/t5/Power-Query/how-to-dynamically-calculate-the-difference-between-2-d... if you have a little time.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors