Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Getting all dates between 2 dates excluding weekends

Hello, 

 

I found this https://community.powerbi.com/t5/Desktop/Getting-all-dates-between-2-dates/m-p/60577/page/2 post, its works however when I wanna apply changes, it says that its not supported  and i cant transfer it to my dashboard. Any suggestions? 

 

Also  is there a way to use networkdays while using this PowerQuery M Method? I would like to display only working days between these dates 🙂 

 

 

Thank you!!!

3 Replies

  • When you say you want to get all the dates between two dates, you mean you want the sum of those days?

    for that there is a function in dax networkingDays q returns the number of working days (you must indicate the holidays of your country ..)

    NETWORKDAYS(, [, , ])

    https://learn.microsoft.com/en-us/dax/networkdays-dax

    Now if what you want is dates like dateTime. I recommend you create another CALENDAR TABLE. Only with the working days. and when you do the beetwen of the two dates you use this table as a reference therefore the DateTime that is there are working days between those two dates ...

    I hope I have helped you in something...

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello,

       

      thank you, well so far I am using PowerApps to calculate Working days between these two dates (From / To) its working, but I need also sequence of days per day. 

       

      The reason : I am doing a lot of calculation and the idea is to view these calculations based on month and quarters and I cant think of any other solution how to incorporate it. So far its displaying my calculation only based on name, country etc...

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     Please refer to my pbix file to see if it helps you.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNNM31jcyVNKBs82UYnWgMqb6pjAJU31zqLiRkb6hob6hAVgGwjEyVYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [startdate = _t, enddate = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"startdate", type date}, {"enddate", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each { Number.From([#"startdate"])..Number.From([#"enddate"]) }),
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
        #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}}),
        #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom.1", each Date.DayOfWeek([Custom],Day.Monday)),
        #"Added Conditional Column" = Table.AddColumn(#"Added Custom1", "Custom.2", each if [Custom.1] >= 5 then "" else [Custom]),
        #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Custom", "Custom.1"})
    in
        #"Removed Columns"

    Best Regards
    Community Support Team _ Polly

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