Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in BI by (11.1k points)

I am using a code

(InitialDate as date, FinalDate as date ) as number => 
let
DaysBetweenDates = Duration.Days(FinalDate-InitialDate),
DaysList = List.Dates(List.Min({InitialDate,FinalDate}),Number.Abs(DaysBetweenDates), Duration.From(1)),
WeekDaysList = List.Select(DaysList, each (Date.DayOfWeek(_, Day.Monday) < 5) ),
WorkingDays = (if DaysBetweenDates < 0 then -1 else 1) * List.Count(WeekDaysList)
in
WorkingDays

How can I use Invoke Custome Function? 

1 Answer

0 votes
by (22.5k points)
edited by

Use a measure:

let
    ValidDates = FinalDate <> null and InitialDate <> null,
    InitialDate = if InitialDate = null then DateTime.LocalNow() else InitialDate,
    FinalDate = if FinalDate = null then DateTime.LocalNow() else FinalDate,
    DaysBetweenDates = if ValidDates then Duration.Days(FinalDate-InitialDate) else 0,
    ...
    WorkingDays =if ValidDates then (if DaysBetweenDates < 0 then -1 else 1) * List.Count(WeekDaysList) else null
    in

Check the power bi training provided by intellipaat 

Also, check out our YouTube video to know the fundaments of Power BI and more

Related questions

0 votes
1 answer
0 votes
1 answer
asked Apr 6, 2021 in BI by Chris (11.1k points)
0 votes
1 answer
asked Feb 25, 2021 in BI by Chris (11.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...