+ Reply to Thread
Results 1 to 4 of 4

Powerbi add number of workdays to current date to return weeknumber

  1. #1
    Registered User
    Join Date
    08-23-2022
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    66

    Powerbi add number of workdays to current date to return weeknumber

    Hi all!

    A quick question. I am trying to work with date calculations in powerbi but am not familiar with the code.
    I have a column with numbers (x) currently formatted as rounded numbers. I would like two new columns:

    Column 1: Today's date + x, not counting saturday and sunday.
    Column 2: the week number that the date in column 1 is in

    For example, its Friday 28-10 today. Number (x) = 12.
    Column 1: 15 nov
    Column 2: 46

    If there is a way to define other days as non-working days too that would be icing on the cake but please don't skip over the solution that only excludes weekend days, as I think going right to the holidays bit will be too complex for me to understand in one go.

    Thanks a lot!

  2. #2
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,381

    Re: Powerbi add number of workdays to current date to return weeknumber

    Take a look at

    https://community.powerbi.com/t5/Des...bi/m-p/2747923
    Last edited by JEC.; 10-28-2022 at 01:56 PM.

  3. #3
    Registered User
    Join Date
    08-23-2022
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    66

    Re: Powerbi add number of workdays to current date to return weeknumber

    Hi JEC.,

    yes, I know that function for "regular" excel formulas and I also understand it enough to be able to use it. There is also quite a lot of information with a simple google search.

    For the equivalent in powerquery I find some answers through google but none are beginner-friendly enough for me to get them to work.

    edit: ah you included a link, will try now

  4. #4
    Registered User
    Join Date
    08-23-2022
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    66

    Re: Powerbi add number of workdays to current date to return weeknumber

    Here's what I ended up using for calculating the date after x workdays:

    = (StartDate as date, WorkDays as number) =>
    let
    WorkDays2 = (WorkDays*2)+7,
    startDate = if Date.DayOfWeek(StartDate)=5 then Date.AddDays(StartDate,2) else
    if Date.DayOfWeek(StartDate)=6 then Date.AddDays(StartDate,1) else StartDate,
    ListOfDates = List.Dates(startDate, WorkDays2,#duration(1,0,0,0)),
    DeleteWeekends = List.Select(ListOfDates, each Date.DayOfWeek(_,1) < 5 ),
    WorkDate = List.Range(DeleteWeekends,WorkDays,1),

    Result = WorkDate{0}

    in
    Result


    And here is converting it to ISO weeknumbers:

    = (Data as date) =>
    let
    Weekday = Date.DayOfWeek(Data) + 1,
    Part1 = Number.From(Data) - Weekday + 11,
    Part2 = Number.From(#date(Date.Year(Date.From(Number.From(Data) + 4 - Weekday)),1,1)),
    Part3 = (Part1 - Part2) / 7,
    Tranc = Part3 - Number.Mod(Part3, 1)
    in
    Tranc

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Highlight column of current weeknumber
    By PatrickEasy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-30-2021, 05:14 AM
  2. Colour Column if current weeknumber
    By GojiPower in forum Excel General
    Replies: 1
    Last Post: 09-02-2016, 10:28 AM
  3. [SOLVED] return weeknumber from date, but only on mondays
    By reluctant in forum Excel General
    Replies: 9
    Last Post: 10-12-2014, 04:29 AM
  4. Formula to look up a date array and return how many workdays between the range
    By delaneybob in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-10-2014, 09:07 AM
  5. Replies: 6
    Last Post: 11-16-2013, 04:29 PM
  6. [SOLVED] Date Formula to Return Week Number in Current Month based on Reporting Period
    By jeversf in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-25-2013, 12:10 PM
  7. Formula to get the current weeknumber
    By Ludde in forum Excel General
    Replies: 2
    Last Post: 09-10-2005, 08:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1