cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
mxfx
Frequent Visitor

query M: Use today if endate is empty

I have a function to calculate elapsed business days between two dates:

mxfx_0-1695753851022.png

It works but if there is no EndDate, it returns an empty cell, I would like it to use "today" if there is no EndDate.

I tried creating a new parameter "Today" which would use the new column "Today" if no EndDate, I also tried with "DateTime. LocalNow" instead of a new parameter but both fail:

 

(StartDate as date, EndDate as date, Today as date, HolidayList as list) as number =>
let
DateList = List.Dates(StartDate, Number.From((if EndDate is null then Today else EndDate) - StartDate) , #duration(1, 0, 0, 0)),
RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5),
RemoveHolidays = List.RemoveItems(RemoveWeekends, List_Holidays),
CountDays = List.Count(RemoveHolidays)
in
CountDays



or


(StartDate as date, EndDate as date, Today as date, HolidayList as list) as number =>
let
DateList = List.Dates(StartDate, Number.From((if EndDate is null then DateTime.LocalNow else EndDate) - StartDate) , #duration(1, 0, 0, 0)),
RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5),
RemoveHolidays = List.RemoveItems(RemoveWeekends, List_Holidays),
CountDays = List.Count(RemoveHolidays)
in
CountDays



1 ACCEPTED SOLUTION
JoeBarry
Solution Sage
Solution Sage

Hi @mxfx 

 

In Power Query, highlight the End Date column and in an empty cell right click and relace value. Enter a fake date.

JoeBarry_0-1695806732190.png

 

 

 

In the formula ribbon replace the fake date

JoeBarry_1-1695806773604.png

 

with 

 

Date.From(DateTime.LocalNow())

JoeBarry_2-1695806825978.png

Thanks

Joe

 

 

If this post helps, then please Accept it as the solution

 

View solution in original post

2 REPLIES 2
mxfx
Frequent Visitor

... don't know how I did not think of that thank you!!

JoeBarry
Solution Sage
Solution Sage

Hi @mxfx 

 

In Power Query, highlight the End Date column and in an empty cell right click and relace value. Enter a fake date.

JoeBarry_0-1695806732190.png

 

 

 

In the formula ribbon replace the fake date

JoeBarry_1-1695806773604.png

 

with 

 

Date.From(DateTime.LocalNow())

JoeBarry_2-1695806825978.png

Thanks

Joe

 

 

If this post helps, then please Accept it as the solution

 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors