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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
AmritaOS
Helper I
Helper I

Network Days Error in Power Query

Hello,

i am trying to calculate network days from two columns of dates. 

StartDate             EndDate

02/02/202102/02/2021
02/02/202103/02/2021
02/02/202108/02/2021
10/03/202119/03/2021
null20/03/2021
02/02/2021null
08/02/202102/02/2021

 

conditional logic:

1. take into account weekends and PublicHolidays1

2. If either of the values are null to return a null

3. if the start date is greater than the created date to return a null

 

here is the function i am using: kindly provided by @Jimmy801 

 

(StartDate as date, EndDate as date) as number =>

let
IntStartDate = if StartDate = null then null else StartDate ,
IntEndDate = if EndDate = null then null 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

 

i am getting this error and am lost as to how to fix it.

Expression.Error: We cannot convert a value of type Table to type List.
Details:
Value=[Table]
Type=[Type]

 

thanks

Amrita

 

1 ACCEPTED SOLUTION

HI Jimmy, i used the TRY and removed the error so all good. thanks!

View solution in original post

5 REPLIES 5
mahoneypat
Microsoft Employee
Microsoft Employee

I suspect your PublicHolidays1 query is in table form, and a list is expected in the function.  Is that the case?  If so, you can replace it with PublicHolidays1[ColumnName], which will pull that single column (replace with actual name of it) from the PublicHolidays1 table as a list.

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


hi pat yes publicholidays1 i have changed the code and its working great - except - i am now gettign this error where the value should return as null

 

Expression.Error: We cannot convert the value null to type Date.
Details:
Value=
Type=[Type]

Hi Amrita, 

 

I am also getting the same error. Did you manage to resolve it?

Hello @AmritaOS 

 

do you still have problems?

 

BR

 

Jimmy

HI Jimmy, i used the TRY and removed the error so all good. thanks!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.