Forum Discussion

jerryr125's avatar
jerryr125
Helper IV
1 year ago
Solved

Creating Rows -Adding Dates

Hi - I would like to create a row for each month/year from the starting data.

Any help would be appreciated!  Jerry

 

Example:

 

Table01 - input (starting data):

 

ProjectCategory 01Category 02Category Date
A20812-2025
B362412-2025
C604812-2025

 

Final Output:

 

ProjectCategory 01Category 02Category Date
A20812-2025
A20811-2025
A20810-2025
A20809-2025
A20808-2025
A20807-2025
A20806-2025
A20805-2025
A20804-2025
A20803-2025
A20802-2025
A20801-2025
B362412-2025
B362411-2025
B362410-2025
B362409-2025
B362408-2025
B362407-2025
B362406-2025
B362405-2025
B362404-2025
B362403-2025
B362402-2025
B362401-2025
C604812-2025
C604811-2025
C604810-2025
C604809-2025
C604808-2025
C604807-2025
C604806-2025
C604805-2025
C604804-2025
C604803-2025
C604802-2025
C604801-2025

 

 

Current Power Query Structure:

 

 

Current Advance Editor:

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Category 01", Int64.Type},
{"Category 02", Int64.Type}, {"Category Date", type date}})
in
#"Changed Type"

 

 

  • Hi jerryr125 ,

     

    speedramps has provided a perfectly good solution already, but I think you'll find this alternative a bit simpler, and it will keep your query a bit cleaner as it's just one step to create the list.

    Use the following formula in a new custom column:

    List.Distinct(
        List.Transform(
            {Number.From(Date.AddMonths([Category Date], -11))..Number.From([Category Date])},
            each Date.StartOfMonth(Date.From(_))
        )
    )

     

    Once you expand the resulting list, you get the following output:

     

     

    Pete

3 Replies

  • Try this ....

     

    In  Power Query add a custom columm

    List.Numbers(1,12)

     

    Expand the list

     

    Add a another custom columm

    Text.From(
    Text.PadStart(Text.From([Custom]), 2, "0")
    )
    &
    "-"
    & 
    Text.From(
    Date.Year([Category Date])
    )

     

     

    Remove the old and temporary custom column and rename the new column to Category Date

     

     

    Please click thumbs up and accept solution.

    Thanks

     

     

  • Hi jerryr125 ,

     

    speedramps has provided a perfectly good solution already, but I think you'll find this alternative a bit simpler, and it will keep your query a bit cleaner as it's just one step to create the list.

    Use the following formula in a new custom column:

    List.Distinct(
        List.Transform(
            {Number.From(Date.AddMonths([Category Date], -11))..Number.From([Category Date])},
            each Date.StartOfMonth(Date.From(_))
        )
    )

     

    Once you expand the resulting list, you get the following output:

     

     

    Pete