Forum Discussion

joshua1990's avatar
joshua1990
Post Prodigy
5 years ago
Solved

Calculate working Dates between two columns

I have a simple table (1) that contains a Date column. Then I have a second table (2) that contains all holidays also on Date level. Is there any chance to determine the number of working days - exc...
  • Fowmy's avatar
    5 years ago

    joshua1990 

    You need to add a custom column with the following M Code in Table 1.

     

     

     

    List.Count(
                if 
                    [Date] > Date.From(DateTime.LocalNow())
                then
                    {}
                else
                
                List.Select(
                    List.Difference(
                        List.Dates(
                            [Date],  
                            Duration.Days
                                (
                                    Date.From(DateTime.LocalNow()) - [Date] 
                                ) + 1
                            ,   
                            #duration(1, 0, 0, 0)
                        ),
                        Holidays[Holiday]
                    ),
                    each Date.DayOfWeek(_,Day.Monday) < 6
                )
            )

     

     

     

     I have attached the file below.