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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
AmritaOS
Helper I
Helper I

Network Days Custom Function

Hello,

i have created a custom function to calculate network days with removing weekends and holidays. however some rows in my start date and some other rown in my end date have null values resulting in an error in the corresponsing custom column.

Also i want to include some conditional logic in teh custom function - if the network days is a negative value than return a blank.

would anyone have any ideas of how to do this? 

 

= (StartDate as date, EndDate as date) as number =>
let
ListDates = List.Dates(StartDate, Number.From(EndDate - StartDate), #duration(1, 0, 0, 0)),
RemoveWeekends = List.Select(ListDates, each Date.DayOfWeek(_, Day.Monday) < 5),
RemoveHolidays = List.RemoveItems(RemoveWeekends, PublicHolidays1),
CountDays = List.Count(RemoveHolidays)
in
CountDays

 

thanks.

Amrita

 

 

2 REPLIES 2
AmritaOS
Helper I
Helper I

HI Jimmy,

Thanks very much this works perfectly!!

regards

Jimmy801
Community Champion
Community Champion

Hello @AmritaOS 

 

I changed your code accordingly to give you some ideas how to deal with your requests

= (StartDate as date, EndDate as date) as number =>
let
IntStartDate = if StartDate =null then YourDateIfStartIsNull else StartDate ,
IntEndDate = if EndDate =null then YourDateIfEndIsNull else EndDate ,
ListDates = List.Dates(IntStartDate, Number.From(IntEndDate - IntStartDate), #duration(1, 0, 0, 0)),
RemoveWeekends = List.Select(ListDates, each Date.DayOfWeek(_, Day.Monday) < 5),
RemoveHolidays = List.RemoveItems(RemoveWeekends, PublicHolidays1),
CountDays = List.Count(RemoveHolidays)
in
if IntStartDate > IntEndDate then null else CountDays


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors