Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jusTodd
Advocate IV
Advocate IV

Create a specific Due Date based on another Date

Curious to know if there is a more effective way of doing this in Power Query.

 

I have a string of dates in which I need to create a due date as the 5th of the following month.

 

This is what I came up with in a Calendar query ... look forward to any feedback.

 

 

let
    Source = #date(2023, 12, 1),
    Custom1 = List.Dates (Source, Number.From(DateTime.LocalNow()) - Number.From(Source), #duration (1,0,0,0)),
    #"Converted to Table" = Table.FromList(Custom1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}}),
    #"Inserted Month" = Table.AddColumn(#"Renamed Columns", "NextMonthDate", each Date.AddMonths([Date],1), Int64.Type),
    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Month",{{"NextMonthDate", type date}}),
    #"Inserted Month1" = Table.AddColumn(#"Changed Type1", "Month", each Date.Month([NextMonthDate]), Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Inserted Month1", "Fifth", each 5),
    #"Inserted Year" = Table.AddColumn(#"Added Custom", "Year", each Date.Year([NextMonthDate]), Int64.Type),
    #"Changed Type2" = Table.TransformColumnTypes(#"Inserted Year",{{"Month", type text}, {"Fifth", type text}, {"Year", type text}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type2", "DueDate", each [Month]&"/"&[Fifth]&"/"&[Year]),
    #"Changed Type3" = Table.TransformColumnTypes(#"Added Custom1",{{"DueDate", type date}})
in
    #"Changed Type3"

 

 

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @jusTodd, check this:

 

 

let
    Source = #date(2023, 12, 1),
    Dates = List.Dates(Source, Duration.TotalDays(Date.From(DateTime.FixedLocalNow()) - Source) +1, #duration (1,0,0,0)),
    ToTable = Table.FromList(Dates, (x)=> {x}, type table[Date=date]),
    Ad_DueDate = Table.AddColumn(ToTable, "DueDate", each Date.AddMonths(#date(Date.Year([Date]), Date.Month([Date]), 5), 1), type date)
in
    Ad_DueDate

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

7 REPLIES 7
dufoq3
Super User
Super User

Hi @jusTodd, check this:

 

 

let
    Source = #date(2023, 12, 1),
    Dates = List.Dates(Source, Duration.TotalDays(Date.From(DateTime.FixedLocalNow()) - Source) +1, #duration (1,0,0,0)),
    ToTable = Table.FromList(Dates, (x)=> {x}, type table[Date=date]),
    Ad_DueDate = Table.AddColumn(ToTable, "DueDate", each Date.AddMonths(#date(Date.Year([Date]), Date.Month([Date]), 5), 1), type date)
in
    Ad_DueDate

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

This puts it on the 5th of the same month ?

 

jusTodd_0-1726685536676.png

 

Hi, no, my query puts 5th of the following month, but at the beginning there was same month - after few minutes I've edited my query, but you probably copied it before my edit 😉 Copy it again.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Yup!  I just got there before you edited.  This works great and is so much more cleaner than my own.  Thanks a bunch!  Really appreciate it.

You're welcome. Enjoy 😉


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Jpss
Resolver II
Resolver II

Hey  @jusTodd 
I recently had to handle a similar scenario that i have documented here. Please check it out.   https://japjeetsodhi.wordpress.com/2024/05/06/generate-dates-between-start-date-and-end-date/

I hope you will find this helpful. 

Thanks for the info!  Got your blog on my feedly now and will try this out to see where else I can use it.  🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.