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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors