Forum Discussion

dave_schultz's avatar
dave_schultz
Regular Visitor
3 years ago
Solved

Business days

Hi all,

 

Is there a way to grab only business days in this formula:

 

let
Source = DateTime.LocalNow(),
#"Converted to Table" = #table(1, {{Source}}),
#"Added Custom1" = Table.AddColumn(#"Converted to Table", "Custom.1", each Date.StartOfDay(Date.AddDays([Column1],-2))),
#"date and time" = #"Added Custom1"{0}[Custom.1]
in
#"date and time"

 

I was considering using the Weekday function and if it returns a 1 or 7, then subtract 3 rather than 2. But that doesn't account for holidays.

 

Thanks! 

 

David

  • Hi , dave_schultz 

    Yes, there is no automatic function in M code to find the corresponding national holidays, you do need to create a date table of your corresponding holidays yourself~

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

4 Replies

  • Hi , dave_schultz 

    According to your description and the M code , do you mean you want to get the first Work day in this week?

    If this , you can try to use this function: Date.StartOfWeek

    Then you can use the Date.AddDays() to get the date you want to .

     

    For more information, you can refer to:
    Date.StartOfWeek - PowerQuery M | Microsoft Learn

    Date.AddDays - PowerQuery M | Microsoft Learn

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • dave_schultz's avatar
      dave_schultz
      Regular Visitor

      Hi v-yueyunzh-msft,

       

      Yes, that helps, but I also want to include US Holiday's. I think I might need to make a calendar to include those holidays.

       

      thanks,

       

      David 

      • v-yueyunzh-msft's avatar
        v-yueyunzh-msft
        Community Support

        Hi , dave_schultz 

        Yes, there is no automatic function in M code to find the corresponding national holidays, you do need to create a date table of your corresponding holidays yourself~

         

        Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

         

        Best Regards,

        Aniya Zhang

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly