• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need M code for calculating next week Monday date in Custom Column

Kelly A

Member
If the current date is 5/12/2023 I would want the custom column to display 5/15/2023 (this data will be dynamic each week).
 

Attachments

  • NextWeekMondayDate.xlsx
    17.8 KB · Views: 4
= Table.AddColumn(#"Changed Type", "Next Monday", each Date.AddDays(Date.EndOfWeek([Current Date]),2), type date)
 
thank you! How can the above M code be updated so that it doesn't figure the custom column on a date column, but uses the current date instead? I tried removing column [Current Date] and replaced it with FixedLocalNow() but not working
 
Last edited:
= Table.AddColumn(#"Changed Type", "Next Monday", each Date.AddDays(Date.EndOfWeek(DateTime.Date(DateTime.FixedLocalNow())),1),type date)
 
Last edited:
So I ran into a problem... the above formula does give me what I need to see BUT there is a row count issue. After I did a merge queries my row count was correct at 517 (in real world) but after I expand that custom column to show only the Next Monday custom column, I am getting in excess of 267,000 rows. I attached a couple of screenshots.
 

Attachments

  • Power Query rowcount Issue.docx
    898.7 KB · Views: 1
So I ran into a problem... the above formula does give me what I need to see BUT there is a row count issue. After I did a merge queries my row count was correct at 517 (in real world) but after I expand that custom column to show only the Next Monday custom column, I am getting in excess of 267,000 rows. I attached a couple of screenshots.
Means you have a one to many result with the merge. If you'd click in the white zone next to a table you can see the preview below. That Will give you a hint. I can't access your file on my phone, so cannot elaborate more for now.
 
My row count was correct at 517 after the merge. Only after I applied the custom column with the formula, then 267,000+ rows was displayed.
 
I am attaching the actual file, please delete it when we are done. There are 2 queries in the workbook. When refreshing the Temp query, the row count increases dramatically at the 'Expanded Custom' Applied Step. Thank you in advance for all of your support!

I got an error message upon upload, "The uploaded file is too large for the server to process." I will try and give you a better indication with new screenshots. Please note after merging queries, I still had a row count of 517.

Please let me know if you need more information or screenshots of something else. I apologize but this is the best I can do.
 

Attachments

  • Power Query Row Count Issue.docx
    800.8 KB · Views: 1
Could you link to a workbook on a file sharing site? There are loads of them (what's more, you'll be in control of their availability).
 
Why are you referencing the Changed Type step in the added column formula rather than the previous step?
 
ok guys, I used the code on my sample file, the data originally has 11 rows, after applying the code and expanding the column, I have 121 rows. I have attached the sample file with the code and query.
 

Attachments

  • NextWeekMondayDate.xlsx
    19.3 KB · Views: 1
Why are you referencing the Changed Type step in the added column formula rather than the previous step?
That is a formula I got in this chat to use for... "How can the above M code be updated so that it doesn't figure the custom column on a date column, but uses the current date instead? I tried removing column [Current Date] and replaced it with FixedLocalNow() but not working."

Another member provided the formula as I am a new pq user. If you have the correct formula for this, please advise me.
 
Back
Top