Calculating the Number of Working Days in Power BI | Custom NETWORKDAYS Function using Power Query

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ม.ค. 2025

ความคิดเห็น • 223

  • @glasbeard
    @glasbeard 10 หลายเดือนก่อน

    I've watched a few videos before finding yours looking for this exact formula. Whilst the other videos may have got there as well, they weren't explaining what each part did, rather just bombarding us with do this, does that! Than you for explaining what each part does so I can now amend to cover my own use. Star! Subscribed 🙂

  • @AK-lj5ze
    @AK-lj5ze 2 ปีที่แล้ว +3

    You've nailed it. Most efficient way of getting things done. Just one small correction though
    List.Dates = List.Dates(StartDate, Number.From(EndDate-StartDate)+1
    +1 at the end gives the right no of days B/W two dates excl Public Holidays & Wknd

    • @logiman
      @logiman ปีที่แล้ว

      Yes. This gets the correct results. Thanks.

    • @jiefang1741
      @jiefang1741 7 หลายเดือนก่อน

      @@logiman No need to +1, there are other videos that use +1, they are so misleading, this is so far the only correct calculation I have seen!!

  • @riyaz540
    @riyaz540 3 ปีที่แล้ว

    Thank you , i advise viewers watch from starting , dont skip .. it is really works ..

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      thanks Riyaz for watching! Happy to hear you got it to work 🙂

  • @lilianaacosta9665
    @lilianaacosta9665 3 ปีที่แล้ว +2

    Excellent solution! Just what I was looking for. Clear and concise.

  • @Hegitman
    @Hegitman 2 ปีที่แล้ว

    Thanks!

    • @HowtoPowerBI
      @HowtoPowerBI  2 ปีที่แล้ว

      thanks Hakan for your support!

  • @Mahmoud-mf8hn
    @Mahmoud-mf8hn 3 ปีที่แล้ว

    I ve been looking for this for 2 days now. thanks man

  • @shalinimenon6248
    @shalinimenon6248 3 ปีที่แล้ว

    Wow... My 2hrs of Google search cane to an end.... 👏

  • @jimanton195
    @jimanton195 3 ปีที่แล้ว

    Thank you very much for this video. I have been working on a solution to this problem for weeks. I have watched a lot of training videos and you definitely have a talent for teaching.

  • @azizony123
    @azizony123 3 ปีที่แล้ว

    Very helpful to my work, very clear, concise and precise discussion, you are a genius...…..thanks for putting this for us

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      You're very welcome! thx for watching!!! 😀

  • @cindyobada7372
    @cindyobada7372 7 หลายเดือนก่อน

    Exactly what I was looking for. Thank you!

  • @annnichakul
    @annnichakul 19 วันที่ผ่านมา

    Thank you, it is very helpful because I find out that it can do it power query.

    • @HowtoPowerBI
      @HowtoPowerBI  19 วันที่ผ่านมา

      Glad it helped 😊

  • @Frenzy511
    @Frenzy511 3 ปีที่แล้ว +1

    Great stuff! Really appreciated this video. I've seen similar solves but this helped me understand the how behind the function.

  • @rachellim4147
    @rachellim4147 3 ปีที่แล้ว +2

    thanks for the video !!! Is there also possible to get ' negative output' for case when actual date is achieved earlier than its target date ?

  • @juliansihas1234
    @juliansihas1234 2 ปีที่แล้ว

    Outstanding Video!! Keep them coming.

  • @FH_EAP
    @FH_EAP 2 ปีที่แล้ว +2

    Hi! Thank you for the useful tutorials! So helpful! Can you provide an update of this video now that PowerBI has rolled out its new NETWORKDAYS function in the July 2022 version? Excited to see your take on it! Thank you!

  • @samcrowson167
    @samcrowson167 3 ปีที่แล้ว +1

    Great video!

  • @908leo
    @908leo 3 ปีที่แล้ว

    Obrigado por compartilhar conhecimento!
    Fique na paz!
    Thanks for sharing knowledge!
    Stay in peace!

  • @diegoacevedo6703
    @diegoacevedo6703 3 ปีที่แล้ว

    Really good explanation! Very clear. Thanks a lot

  • @Fiktage
    @Fiktage 2 ปีที่แล้ว

    Oh!!! With music in the background, learning productivity is better :)

    • @HowtoPowerBI
      @HowtoPowerBI  2 ปีที่แล้ว +1

      oh nooo - my newer vids don't have any music 😄😆 - thx for watchn Alexandr

    • @Fiktage
      @Fiktage 2 ปีที่แล้ว

      @@HowtoPowerBI area for improvement, even your video content is awesome! :)))

  • @alejandroelkabish
    @alejandroelkabish 2 ปีที่แล้ว

    I will try this however weekends in my country Is different. You’re awesome anyways

  • @mannisingh1313
    @mannisingh1313 4 ปีที่แล้ว

    Thank you very much for providing such a useful function and a great way to explain it. It works perfect for me and now i am your proud subscriber too :)

    • @HowtoPowerBI
      @HowtoPowerBI  4 ปีที่แล้ว +1

      great to hear it was helpful, thx for your sub! 😃

  • @dag06001
    @dag06001 4 หลายเดือนก่อน +1

    The first function works great. How would I then remove a list of Holidays from the Workdays?

  • @kel78v2
    @kel78v2 ปีที่แล้ว

    The function is not supported in DirectQuery mode? Am looking for an alternative to the out of the box networkdays that works for directquery.

  • @PB-vx4nc
    @PB-vx4nc 2 ปีที่แล้ว

    Thanks, I have used it and it helps a lot, however i have to add one more condition where we shud check if there's any Month Start in between weeks, in such case the iteration shud start with the month start 😅

  • @AndyJones-t3e
    @AndyJones-t3e 5 หลายเดือนก่อน

    in my data I have start dates that are before the end date so the count is a minus (this is expected in the data set). This gives me an expression error. The 'count' argument is out of range as its a minus number. any ways around this so it returns the minus number ?

  • @DonovanBisset
    @DonovanBisset 2 ปีที่แล้ว +2

    I can’t find the custom code for this video?

  • @EricMammen-s9j
    @EricMammen-s9j ปีที่แล้ว +2

    Hi, Love the content! I used this about a year ago, but now we have NETWORKDAYS in PowerBI. Of course, now I'm trying to create a due date where I have a start date, number of days and want to find the due date. (So just like WORKDAY in Excel). Any chance you have a solution for this? Thanks

  • @ElWiwif
    @ElWiwif 2 ปีที่แล้ว

    Thank you and your beard man. Keep sharing

    • @HowtoPowerBI
      @HowtoPowerBI  2 ปีที่แล้ว

      :):) haha 😂 will do!!

  • @gopinathn9059
    @gopinathn9059 2 ปีที่แล้ว

    Awesome Video Thanks for your great help

    • @HowtoPowerBI
      @HowtoPowerBI  2 ปีที่แล้ว +1

      Glad it helped! thx Gopinath

    • @gopinathn9059
      @gopinathn9059 2 ปีที่แล้ว

      Bro I have come across a specific issue from this Custom function. If Start Date or End Date falling on Holiday or Weekend count is not excluded. Please guide me.

  • @juandiegotorres4287
    @juandiegotorres4287 3 ปีที่แล้ว

    Thank you so much man!

  • @cg24356
    @cg24356 3 ปีที่แล้ว +1

    Just great!!!

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว +1

      thank you for watching Clemens!!! 😀

    • @cg24356
      @cg24356 3 ปีที่แล้ว

      @@HowtoPowerBI one thing: I am just wondering why you get the right result in column "Tot No Days excl Weekends 2" at minute 12:54 before you added "Holidays as list" in your custom function "NETWORKDAYS". I first had to add this parameter "Holidays as list" in my function, then it worked. Before I got an error saying that there was a third parameter expected but only 2 found... something like this. I did it in Excel Power Query, not Power BI. Maybe that's the reason

  • @rhearivamonte490
    @rhearivamonte490 3 ปีที่แล้ว

    Sooooo helpful. Thank you 🙂

  • @tylerhoops8270
    @tylerhoops8270 3 ปีที่แล้ว

    Incredible! I've been looking for a quick solution to this for ages.
    Thank you!

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      if I only knew, then I would have uploaded it earlier 😁😉 ... happy it helped!

  • @AmritaOSullivan
    @AmritaOSullivan 3 ปีที่แล้ว

    this was brilliant thank you!!

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      thanks Amrita! too much credit! 😊😃

  • @suletopcu6013
    @suletopcu6013 5 หลายเดือนก่อน

    On question. How can we translate this formula into a conditional form? If some data does not have a closed date, if we want it to calculate from today() instead of closed date? Thank you very much!

  • @DarrenDRozario
    @DarrenDRozario 2 ปีที่แล้ว

    Um, I can't find the code you've used to copy into a blank query, mentioned in the description area?

  • @anshade3271
    @anshade3271 4 ปีที่แล้ว

    This was so helpful 👍 thank you

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว +1

      awesome, happy it helped!! 😃

  • @aelwyne6167
    @aelwyne6167 3 ปีที่แล้ว

    Thank you sooo much it was very helpfull and nice learning video.

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      Glad it was helpful! 😀

  • @jasonpdy
    @jasonpdy 3 ปีที่แล้ว

    Thank you from Shanghai

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      thx for watching Jason! greetings from Düsseldorf 😉

  • @yanelam1418
    @yanelam1418 2 ปีที่แล้ว

    Great solution, I would love to see how display the measure in graphs.

    • @HowtoPowerBI
      @HowtoPowerBI  2 ปีที่แล้ว

      thanks 🙂there is no measure in this video though

  • @sandeepchourasia404
    @sandeepchourasia404 3 ปีที่แล้ว

    Hi - how about - if I also want to find the difference(duration) by working hours? for instance - I have working hours as 0900 to 1700. And I wish to calculate the duration, in hours, from say - StartDATETIME as Friday, dd/mm/yyyy 15:35:40 to EndDATETIME as Monday, dd/mm/yyyy 10:15:35? The duration must only consider the business working hrs difference?

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      you would need to extend the logic a bit -
      (1) you can multiply by 8 for all days except the start and end date
      (2) for the start and end date you would need to calculate separately the hours and add it to the result of (1)

    • @sandeepchourasia404
      @sandeepchourasia404 3 ปีที่แล้ว

      @@HowtoPowerBI -The logic you gave is clear :), but the question is how to program the above two step logic in Power Query. :)

  • @tj6544
    @tj6544 2 ปีที่แล้ว

    Cannot find the link in the description for the M script. Someone please point it to me. Thanks

  • @smitherbeanz
    @smitherbeanz 2 ปีที่แล้ว

    Hi! I have projects that overlap dates and would like to show the total # of days employees have work planned in a year? I have the duration of projects from start to end, but I'm STRUGGLING to figure out how to exclude the days where projects overlap. Do you how I would write a measure to do this? Thank you for all the vids and helping us pbi newbs🙏🏼

  • @daremo4748
    @daremo4748 11 หลายเดือนก่อน

    Thank you. ❤

    • @HowtoPowerBI
      @HowtoPowerBI  11 หลายเดือนก่อน

      You're welcome 😊

  • @gurukirangowdak1155
    @gurukirangowdak1155 3 ปีที่แล้ว

    Hi, I have learnt So many things from your video. The way of explaining is so nice and easy to understand. Here instead of removing holiday and counting, how to remove for previlaged leave example:- let there are two E1and E2,E1 start date is 1-1-2020 and end date is 6-1-2020 and E2 start date 2-1-2020 and end date is 5-1-202, where E1 takes leave on 1-1-2020 and 4-1-2020 and E2 takes leave on 6-1-2020, then number of workday for E1 is 4(work day-no of leave) and number of workday for E2 is 4 days because the leave he has taken does not come in his work day, E2 leave comes under workday of E1 it should not affect on that because E1 has taken only two leave and its come under his workday therfore E1 workday is 6-2=4 how to count this one.

  • @nilseckert2596
    @nilseckert2596 2 ปีที่แล้ว

    Great Video! If I import the exact same code for the holidays it takes ages until it loads the data in. Before I just hat removed the weekends and it worked great and fast. Any idea why the data load takes so lang after I typed in the holiday function?

  • @andreadellaquila3622
    @andreadellaquila3622 ปีที่แล้ว

    Do you have a similar video that calculates a Due Date based on 30 working days excluding weekends and holidays?

  • @metchau5354
    @metchau5354 3 ปีที่แล้ว +1

    I put in the function but the calculation on working days in a month for some months is off by 8 hours. Trying to figure out how to correct this.

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      Adding 1 day to the number of days between start and end corrected the issue and the PowerQuery function output matches the Excel function output.
      (StartDate as date, EndDate as date) as number =>
      let
      ListDates = List.Dates(StartDate, Number.From(EndDate-StartDate) +1 , #duration(1, 0, 0, 0)),
      RemoveWeekends = List.Select(ListDates, each Date.DayOfWeek(_,Day.Monday) < 5),
      CountDays = List.Count(RemoveWeekends)
      in
      CountDays

    • @metchau5354
      @metchau5354 3 ปีที่แล้ว

      @@HowtoPowerBI Thanks! This works great!

  • @gandako6782
    @gandako6782 3 ปีที่แล้ว

    Thank you!!! You are so cool :D

  • @zzzzzzzzzzzzzzzz9
    @zzzzzzzzzzzzzzzz9 4 ปีที่แล้ว

    Wonderful, i can use this. Thank you Bas

  • @lukeandchitraswygard8567
    @lukeandchitraswygard8567 4 ปีที่แล้ว +1

    This was so helpful! Thank you!!! So my issue is I need to know how many work days it has been since today. I have never used M so I’m not sure the best way to do this. I can make it work by creating a custom column with today’s date and then using that as the end date to pass in to the function, but it seems like there would be a better way, right? Thank you so much!

    • @HowtoPowerBI
      @HowtoPowerBI  4 ปีที่แล้ว +1

      you can adjust the function so that it takes today as the end date. Replace each reference to the enddate in the function with DateTime.Date(DateTime.LocalNow()) . Hope this helps 🙂

    • @lukeandchitraswygard8567
      @lukeandchitraswygard8567 4 ปีที่แล้ว +1

      Thank you!

    • @PraveenKumarJasoriya
      @PraveenKumarJasoriya 3 ปีที่แล้ว

      @@lukeandchitraswygard8567 does it work, if yes can you share the code

  • @billking8732
    @billking8732 3 ปีที่แล้ว +1

    Great video, great delivery, very informative! I do have a question however. While my Power query results match your results perfectly, they don’t always match the original NETWORKDAYS function in Excel. At 11:00 of your video in row 9 you shows 16 days for your start and end dates; However, if you use the function in Excel, the result is 17 days. Can you please address this discrepancy. (This is before you address holidays, by the way.)

    • @hl3341
      @hl3341 2 ปีที่แล้ว

      I have the same question. I'm not sure if I am articulating it right but it seems like the function is counting the difference is days and not the true count of days.

    • @hl3341
      @hl3341 2 ปีที่แล้ว

      solution is mentioned in below comment on this if you havent already seen it.

  • @hl3341
    @hl3341 2 ปีที่แล้ว

    How can I do this for datetime inputs and output a decimal for the duration??

  • @mosabbah
    @mosabbah 2 ปีที่แล้ว

    Hey, Thanks for the amazing video, But I got an Error "Expression.Error: The 'increment' argument is out of range.
    Details:
    1.00:00:00" Could you help me with that please

  • @vikrammankar4083
    @vikrammankar4083 2 ปีที่แล้ว

    Hi, I am unable to see the description section. Can somebody please help, where can i see the description section

  • @picnicrotation
    @picnicrotation ปีที่แล้ว

    how can I have it use "today" as end date if the end date column is empty?

  • @zainebmalik5142
    @zainebmalik5142 2 ปีที่แล้ว

    What if the start date or end date is sometimes blank? Is there a condition I can use in that case?

  • @DuncanLon
    @DuncanLon 3 ปีที่แล้ว +4

    thank you for this video! In the end, you say that sometimes it's better to perform calculations in DAX, sometimes in the Query Editor. Do you have a video to explain how you decide where to perform the calculations? To me, it's still a bit random.

  • @jrgomez7340
    @jrgomez7340 7 หลายเดือนก่อน

    This is very helpful. What if it's date-time instead of just dates? I'm getting integers in total working days.

  • @gauthamk1485
    @gauthamk1485 3 ปีที่แล้ว

    Awesome as always... learning something new is incredible
    My Query: how to apply a logic if we have multiple countries with various holidays. How to create custom function?

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว +1

      thx!! 🙂 you can expand the logic and use multiple holiday lists. You then check with an if statement what the country is and dependent on that subtract the holidays in the corresponding list for that country.

    • @gauthamk1485
      @gauthamk1485 3 ปีที่แล้ว

      @@HowtoPowerBI Thanks Bas. Will try and keep you posted 🙂

  • @WendersonReisss
    @WendersonReisss 3 ปีที่แล้ว

    How can I calculate work hour on Power BI?
    For example: date and time start "09/15/2021 07:00 a.m" and date and time process finished "10/15/2021 08:30 a.m". The duration (result) of this process between this date and time is = 11:30 hours (without count Full 24 hours, just count work time available).
    The period of job starts at 7:00 a.m and the end is 5:00 p.m.
    I need Just count
    Thank you!

  • @PB-vx4nc
    @PB-vx4nc 3 ปีที่แล้ว

    Thank You So much.....I have used it but some how if my end date is on Saturday of Feb'2021 (I tried with only 2months data), it is including Saturday also in to my Network Day. Rest it's working all correct. Any suggestion

  • @manrajdhindsa3572
    @manrajdhindsa3572 2 ปีที่แล้ว

    Hey, great stuff! Is there a way to stop the calculation once a certain criteria is met?
    I want to count the number of days from the start date but I want the counter to stop once the order has been shipped. Current calculator continues the count even if the order has been shipped out.

  • @markhenderson3771
    @markhenderson3771 2 ปีที่แล้ว

    Thank you. This was tremendously useful. I am creating my date table in a dataflow, so I need to use m language (Power Query). If I have my holidays in a table (coming from an Excel spreadsheet), how do I create a list?

  • @nabeelalmoalimi5417
    @nabeelalmoalimi5417 ปีที่แล้ว

    I could not find the dax script for this query!

    • @HowtoPowerBI
      @HowtoPowerBI  ปีที่แล้ว

      it is not dax, it is M power query ... see download link in the description

  • @brixtoclixfavt9827
    @brixtoclixfavt9827 2 ปีที่แล้ว

    I am not able to utilize this function on visual. Any help here please?

  • @kunalr_ai
    @kunalr_ai 4 ปีที่แล้ว +1

    thanks for the title ... landed here because of the title of this video

  • @maijai
    @maijai 3 ปีที่แล้ว

    Love it great contribution, thanks! I have a list with over 100K lines which take for ever to calculate as the list of dates to be excluded adds up to probably about 10K lines. Any hint on how this could be optimized furhter?

  • @Mohammad-rp2bt
    @Mohammad-rp2bt 3 ปีที่แล้ว

    Great stuff!
    How to custom select the day of the week which I want to exclude as the holiday?
    For example if I only want to exclude Friday
    & my week starts on Sunday

  • @burlandb
    @burlandb 3 ปีที่แล้ว

    I cannot get the remove holidays to work??

  • @AlAmineDiagne
    @AlAmineDiagne 2 ปีที่แล้ว

    Hello Bass, thanks for this video it is very helpful but can a do with Power Query on how to calculate Sick Leave please. Thanks Again

  • @danieviljoen5911
    @danieviljoen5911 4 หลายเดือนก่อน

    Hi Bas, how can we create the list of the dates that we count?

  • @mohammadmazhar6184
    @mohammadmazhar6184 3 ปีที่แล้ว

    Hi, i need to calculate time duration between 2 columns having date and time in each column (just working day's which means excluding weekends). Could you help?. Many thanks in advance.

  • @pabhay235
    @pabhay235 2 ปีที่แล้ว

    EXCELLENT

  • @huluwa8146
    @huluwa8146 2 ปีที่แล้ว

    Where can I find a good holiday dates csv?

  • @PraveenKumarJasoriya
    @PraveenKumarJasoriya 3 ปีที่แล้ว

    what code should we write if end date needs to be the systems date

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      for the end date you can then take DateTime.Date(DateTime.LocalNow())

  • @gayathrireddy4110
    @gayathrireddy4110 3 ปีที่แล้ว

    Hi
    Thank you for the video but I wanted to know if it is possible to consider working hours while calculating the difference

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      think so, haven't tried though - sounds like a nice idea for a follow-up video 🙂

    • @MrSenthil99
      @MrSenthil99 3 ปีที่แล้ว

      @@HowtoPowerBI Good Day - Please could you assist - I found this video on Calculating Business Hours with Dax -> th-cam.com/video/_O8o6Hxuyjk/w-d-xo.html - Is there an easier way to do this ?

  • @infy25
    @infy25 3 ปีที่แล้ว

    Hi Bas, thank you so much for this video. 1 question how to add if condition along with this.
    As an example, if the status is closed then calculate network days.

  • @colleenlucero
    @colleenlucero ปีที่แล้ว

    Hey! This is exactly what I've been trying to do. So helpful to come across this video. Thank you!
    Question though: I'm calculating the working day of each month. So my start date is the start date of the month and the end date is the date colum. On weekends I noticed it is still calculating a number... It's just a repeat. For example:
    1/1/23 holiday counted as 1
    1/2/23 weekend counted as 1
    1/3/23 actual workday 1 - counted as 1
    Is there a better way I could display this so my end users know which one is the true workday?
    So I end up with 3, 1's
    1/17/23

  • @harikrishnareddy2700
    @harikrishnareddy2700 2 ปีที่แล้ว

    Thanks a lot .. need to add 1 to the formula as it results 1 less

  • @lucassteibert6007
    @lucassteibert6007 3 ปีที่แล้ว

    Hello Bas, really good explanation. I have a further question: What if my EndDate is earlier than my StartDate? I want also to calculate the negative ranges in order to get delay figures. In my case if I simulate the function with StartDate > EndDate, I receive the following error message: "Expression.Error: The 'increment' argument is out of range.
    Details: 1.00:00:00" Is it possible to also calculate negative ranges with this custom function? Would be really nice, if you could answer.

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      you could add an if statement to check if the enddate is before the startdate and multiply by -1 if it is
      = (StartDate as date, EndDate as date) as number =>
      let
      DateList =
      if EndDate < StartDate then
      List.Dates(StartDate, Number.From(StartDate - EndDate), #duration(1, 0, 0, 0)) else
      List.Dates(StartDate, Number.From(EndDate - StartDate), #duration(1, 0, 0, 0)),
      RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5),
      CountDays = List.Count(RemoveWeekends)
      in
      -CountDays

    • @carlosrebatorodriguez3771
      @carlosrebatorodriguez3771 3 ปีที่แล้ว +3

      ​@@HowtoPowerBI Hi Bas, thanks for the video. The statement works but then all values returns in negative. In my database StartDate can be >, = or < EndDate. How this function coulf return - 0 or +?

  • @roydramirezv
    @roydramirezv 3 ปีที่แล้ว +1

    Great video, would any body tell me why this formula works fine in my pc but in the pc of my partner doest't work?, the error says "the list appear is not complete" but the list of holidays is fine and was transformed as a list, I don't know if there are a mistake

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      can you clear cache and see if this fixed it?

  • @ZSXXSpace
    @ZSXXSpace 3 ปีที่แล้ว

    Hi Bas, can you please advise how can we add the time into the customs function? Thanks

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      #time(hour as number, minute as number, second as number) as time .. for example, #time(1, 30, 0) would be 1 hour 30 min

  • @jasonsupplee1924
    @jasonsupplee1924 3 ปีที่แล้ว

    Well I wanted this to work. I followed the instructions but when trying to use the "NetworkDays" function in a column I just get "Failed to resolve name 'NetworkDays'. It is not a valid table, variable or function name."

    • @jasonsupplee1924
      @jasonsupplee1924 3 ปีที่แล้ว

      Oh I needed to do the custom column in the power query, got it.

  • @wodzimierzgornicki7921
    @wodzimierzgornicki7921 2 ปีที่แล้ว

    how to add if statement here? I want to skip all these rows that have an empty start or end date
    please help

  • @AjithKumar-fz4mq
    @AjithKumar-fz4mq 2 ปีที่แล้ว

    HI I am not able to find the function to copy it.

    • @HowtoPowerBI
      @HowtoPowerBI  2 ปีที่แล้ว

      You can download the file from the link i the description. Open it, go to transform data, query editor :)

    • @AjithKumar-fz4mq
      @AjithKumar-fz4mq 2 ปีที่แล้ว

      @@HowtoPowerBI Sorry The download link is taking to the video again and I don't see any file download there.

    • @AjithKumar-fz4mq
      @AjithKumar-fz4mq 2 ปีที่แล้ว

      @@HowtoPowerBI Got it. Thanks for the Quick reply.

  • @AmritaOSullivan
    @AmritaOSullivan 3 ปีที่แล้ว

    Hi Bas, i am using this exact method but am getting some numbers and some error values. both the start date and the end date have some nulls in the rows and that is where the error is coming. my requirement is the eventually calculate the average days between the start and end date but with the errors it is not allowing me to do so. would you know a solution for this please? thanks!!

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว +1

      Hi Amrita, you could use the try / otherwise statement -> = Table.AddColumn(#"Added Custom1", "networksdays", each try NetworkDays([Start Date],[End Date], Holidays) otherwise null)

    • @AmritaOSullivan
      @AmritaOSullivan 3 ปีที่แล้ว

      @@HowtoPowerBI thank you this is perfect!! works!

  • @briefkastenjonas
    @briefkastenjonas 4 ปีที่แล้ว

    @How to Power BI First of all thank you and it works. But can I somehow use this as a filter to switch between workings days and all days?

    • @HowtoPowerBI
      @HowtoPowerBI  4 ปีที่แล้ว +1

      you can create two measures, one that sums up the all days column and one that sums up the workdays column. Then you can use a slicer to switch between the two. I will make a video on how to do that. In the meantime I think this video from curbal answers how to set it up th-cam.com/video/gYbGNeYD4OY/w-d-xo.html

    • @briefkastenjonas
      @briefkastenjonas 4 ปีที่แล้ว

      @@HowtoPowerBI Thank you for your quick response! I looking forward to your next video.

  • @ritikapandey
    @ritikapandey 3 ปีที่แล้ว

    Very informative. Thanks for explaining it so nicely. Best video so far.
    However, what to do if there are records where the End Date isn't there? For eg when we are looking at sales data with both closed and open opportunities and the open ones won't have any Closed Date as such. In this scenario, the calculated column throws an error. Any way to handle that?
    Thanks in advance!

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      thx Ritika!! 😀

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว +1

      you can use try ... otherwise .. and return null instead of error
      (StartDate as date, EndDate as date, optional Holidays as list) =>
      let
      DateList = List.Dates(StartDate, Number.From(EndDate - StartDate)+1, #duration(1, 0, 0, 0)),
      RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5),
      //RemoveHolidays = List.RemoveItems(RemoveWeekends, Holidays),
      CountDays = List.Count(RemoveWeekends)
      in
      try CountDays otherwise null

    • @sandraespinach3959
      @sandraespinach3959 3 ปีที่แล้ว +1

      @@HowtoPowerBI This is great! But even adding "try CountDays otherwise null" the query still gives an error and I can apply it. Any other suggestion? Thank you in advance!

  • @TorPid9
    @TorPid9 2 ปีที่แล้ว

    Nice video, is there anyway that both start and end days is also counted?

    • @HowtoPowerBI
      @HowtoPowerBI  2 ปีที่แล้ว

      thx Mahdi - you can add plus 1 -> List.Dates = List.Dates(StartDate, Number.From(EndDate-StartDate)+1

  • @gregheath9071
    @gregheath9071 4 ปีที่แล้ว +2

    I do not get the same number of working days as the standard excel function.
    Here is my function:
    (StartDate as date, EndDate as date) as number =>
    let
    ListDates = List.Dates(StartDate, Number.From(EndDate-StartDate), #duration(1, 0, 0, 0)),
    RemoveWeekends = List.Select(ListDates, each Date.DayOfWeek(_,Day.Monday) < 5),
    CountDays = List.Count(RemoveWeekends)
    in
    CountDays
    If I pass Start Date = 3/1/2020, 3/31/2020 the function returns 21 week days but March has 22 week days.

    • @gregheath9071
      @gregheath9071 4 ปีที่แล้ว +1

      Adding 1 day to the number of days between start and end corrected the issue and the PowerQuery function output matches the Excel function output.
      (StartDate as date, EndDate as date) as number =>
      let
      ListDates = List.Dates(StartDate, Number.From(EndDate-StartDate)+1, #duration(1, 0, 0, 0)),
      RemoveWeekends = List.Select(ListDates, each Date.DayOfWeek(_,Day.Monday) < 5),
      CountDays = List.Count(RemoveWeekends)
      in
      CountDays

    • @HowtoPowerBI
      @HowtoPowerBI  4 ปีที่แล้ว

      thanks for bringing it up and sharing your solution!

  • @manuelaguilar3523
    @manuelaguilar3523 2 ปีที่แล้ว

    Good morning. Thanks in advance for this great video. It was such as helpful for me. But, how can I add extra hours of shifts to function? Thanks in advance

  • @imconfused1237
    @imconfused1237 4 ปีที่แล้ว

    This is awesome! It’s so bizarre that PowerBI doesn’t have this natively, especially when its relevance is already recognised within Excel 🤷‍♂️
    Got a question for you: I have a dataset which generates 20k rows each month. The time variables are: Opened (datetime), Closed (datetime) One of the calculations is Working Days between these datestamps, returned as a whole number.
    I’m keen to maintain a lean and efficient dataset and bringing 20k datestamp rows will surely bloat the cardinality! Is it possible, using a function like this, to calculate the working days within PowerQuery, bring this custom column in and then discard the original Open and Closed columns?
    So, instead of a bunch of dates and times, I can bring the metric in (which is a primary feed into an MTTR analytic) ?

    • @NewUnit13
      @NewUnit13 4 ปีที่แล้ว +1

      If you don't need the open or close times for your model then sure, you could definitely do that. Another way you can reduce the cardinality and keep the dimension is to split them apart. make a single date and a single time column then remove the original open/close datetime column.

    • @imconfused1237
      @imconfused1237 4 ปีที่แล้ว

      @@NewUnit13 That’s a great shout! I hadn’t thought of that at all. I mean I could probably do with keeping one date dimension (Closed) as a month identifier, as it’d save me extracting it from the file name string.
      Some great food for thought - many thanks for your reply and guidance 😀👍

    • @HowtoPowerBI
      @HowtoPowerBI  4 ปีที่แล้ว

      Edward makes a good point, split the date time. Keep in mind that you can also use DAX to return the net working days

  • @deepside7
    @deepside7 2 ปีที่แล้ว +1

    Great Video - Any suggestions on how to add business days to a start date? (and then exclude public holidays etc. too)

  • @sachin.tandon
    @sachin.tandon 4 ปีที่แล้ว

    This is great. But how do you extend the functions for a third argument, for region, as weekends and public holidays aren't the same globally, but can vary by region, e.g. Australia, vs U.A.E.?

    • @HowtoPowerBI
      @HowtoPowerBI  4 ปีที่แล้ว +1

      The formula from the video already contains that as a third argument. Just refer add a list with the holidays you need eg Australia and then refer to that in the function -> NetworkDays([Start Date],[End Date], Holidays_Australia)

    • @sachin.tandon
      @sachin.tandon 4 ปีที่แล้ว

      @@HowtoPowerBI What if weekends also vary by region - e.g. Australia vs U.A.E. - how do you accommodate for both W/Es and Holidays?

    • @HowtoPowerBI
      @HowtoPowerBI  4 ปีที่แล้ว +1

      @@sachin.tandon You can adapt this line to the rule you need for the weekends -> RemoveWeekends = List.Select(ListDates, each Date.DayOfWeek(_,Day.Monday) < 5),

  • @emegd9128
    @emegd9128 3 ปีที่แล้ว

    How can you make this work for TODAY() instead of and end date? Thanks

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      replace end date with todays date Date.From(DateTime.LocalNow())

  • @smvpegb
    @smvpegb 3 ปีที่แล้ว

    Thanks fpr share it!
    but there are i dont understand. if my start date is July 1 and EndDate is July 7.... why is returning 4??
    Considering that July 1 is thusrday and July 7 is Wednesday ... between these 2 days are 5 not 4

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      it is not counting the start date itself .. just add 1 after Number.From(EndDate - StartDate) and that will fix it
      (StartDate as date, optional EndDate as date, optional Holidays as list) =>
      let
      DateList = List.Dates(StartDate, Number.From(EndDate - StartDate)+1, #duration(1, 0, 0, 0)),
      RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5),
      //RemoveHolidays = List.RemoveItems(RemoveWeekends, Holidays),
      CountDays = List.Count(RemoveWeekends)
      in
      try CountDays otherwise null

  • @michellemasters7221
    @michellemasters7221 3 ปีที่แล้ว

    I do not see the function anywhere for me to copy

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว +1

      there is a download in the description from which you can download the file with the function to copy.
      (StartDate as date, EndDate as date, Holidays as list) as number =>
      let
      DateList = List.Dates(StartDate, Number.From(EndDate - StartDate), #duration(1, 0, 0, 0)),
      RemoveWeekends = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday) < 5),
      RemoveHolidays = List.RemoveItems(RemoveWeekends, Holidays),
      CountDays = List.Count(RemoveHolidays)
      in
      CountDays

  • @mohsinmanzoor2483
    @mohsinmanzoor2483 3 ปีที่แล้ว

    it throws error when we have start and end dates in date/time format.
    How to fix that???

    • @HowtoPowerBI
      @HowtoPowerBI  3 ปีที่แล้ว

      you can wrap the dates in a Date.From function - adjust the references to start / end date like this --> Date.From(StartDate)

  • @srikapil6711
    @srikapil6711 2 ปีที่แล้ว

    Hi I tried entering the same code using the same steps but when I am trying to test using invoke it gives an error as
    An error occurred in the " query. Expression. Error: we cannot convert a value of type function to type List details
    Value =[Function]
    Type =[Type]
    Could you please help me fix this

    • @srikapil6711
      @srikapil6711 2 ปีที่แล้ว +1

      I think I figured it out and this code is working fine for me thanks a lot for the Video

    • @HowtoPowerBI
      @HowtoPowerBI  2 ปีที่แล้ว +1

      aaah I'm too slow 😉 happy to hear your already have it figured out

    • @srikapil6711
      @srikapil6711 2 ปีที่แล้ว

      @@HowtoPowerBI thanks a lot the code really helped me