Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext 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
Hello,
i am trying to calculate network days from two columns of dates.
StartDate EndDate
| 02/02/2021 | 02/02/2021 |
| 02/02/2021 | 03/02/2021 |
| 02/02/2021 | 08/02/2021 |
| 10/03/2021 | 19/03/2021 |
| null | 20/03/2021 |
| 02/02/2021 | null |
| 08/02/2021 | 02/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
Solved! Go to Solution.
HI Jimmy, i used the TRY and removed the error so all good. thanks!
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
To learn more about Power BI, follow me on Twitter or subscribe 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?
HI Jimmy, i used the TRY and removed the error so all good. thanks!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 5 | |
| 5 | |
| 4 |