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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mterry
Helper V
Helper V

Duplicate Rows & Add Dates

I have a data set with annual info, wondering if it's easy in Power Query to duplicate each row 11x and add a separate column with a corresponding month?

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @mterry ,

 

Please try to create a new table using DAX:

New Table = 
var _date=FILTER(CALENDAR(DATE(YEAR(TODAY()),1,1),DATE(YEAR(TODAY()),12,31)),DAY([Date])=1)
return CROSSJOIN('Table',_date)

Or 

New Table2 = 
var _date=SELECTCOLUMNS( GENERATESERIES(1,12,1),"Date",CONVERT( YEAR(TODAY())&"-"&[Value]&"-1",DATETIME))
return CROSSJOIN('Table',_date)

Output:

Eyelyn9_0-1650255896142.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcizOTFTSUQrJyMxLNwQyDA0MDJRidaKV3IoS85JTYVJGQIYpTCo0GCZsDGQYgYVjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Region = _t, Thing = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Region", type text}, {"Thing", type text}, {"Amount", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {1..12}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Date", each "1/"&Number.ToText([Custom])&"/2022"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Custom"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @mterry ,

 

Please try to create a new table using DAX:

New Table = 
var _date=FILTER(CALENDAR(DATE(YEAR(TODAY()),1,1),DATE(YEAR(TODAY()),12,31)),DAY([Date])=1)
return CROSSJOIN('Table',_date)

Or 

New Table2 = 
var _date=SELECTCOLUMNS( GENERATESERIES(1,12,1),"Date",CONVERT( YEAR(TODAY())&"-"&[Value]&"-1",DATETIME))
return CROSSJOIN('Table',_date)

Output:

Eyelyn9_0-1650255896142.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

How would the DAX change if trying to add dates for every day in the year, instead of every month of the year?

I had to make some tweaks, but your reply got me there using the date variable and CROSSJOIN, which I was not familiar with. Thanks

VahidDM
Super User
Super User

@mterry 

 

It sould be great if you share a sample of your data set here in a text format.

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

I can't provide the actual data, but below is a sample of what I have, and what I would like it to look like:

 

RegionThingAmount
AsiaThing11000
FranceThing25000
USThing32000

 

What I would like:

 

RegionThingsAmountDate
AsiaThing110001/1/2022
AsiaThing110002/1/2022
AsiaThing110003/1/2022
AsiaThing110004/1/2022
AsiaThing110005/1/2022
AsiaThing110006/1/2022
AsiaThing110007/1/2022
AsiaThing110008/1/2022
AsiaThing110009/1/2022
AsiaThing1100010/1/2022
AsiaThing1100011/1/2022
AsiaThing1100012/1/2022
FranceThing250001/1/2022
FranceThing250002/1/2022
FranceThing250003/1/2022
FranceThing250004/1/2022
FranceThing250005/1/2022
FranceThing250006/1/2022
FranceThing250007/1/2022
FranceThing250008/1/2022
FranceThing250009/1/2022
FranceThing2500010/1/2022
FranceThing2500011/1/2022
FranceThing2500012/1/2022
USThing320001/1/2022
USThing320002/1/2022
USThing320003/1/2022
USThing320004/1/2022
USThing320005/1/2022
USThing320006/1/2022
USThing320007/1/2022
USThing320008/1/2022
USThing320009/1/2022
USThing3200010/1/2022
USThing3200011/1/2022
USThing3200012/1/2022

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcizOTFTSUQrJyMxLNwQyDA0MDJRidaKV3IoS85JTYVJGQIYpTCo0GCZsDGQYgYVjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Region = _t, Thing = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Region", type text}, {"Thing", type text}, {"Amount", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {1..12}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Date", each "1/"&Number.ToText([Custom])&"/2022"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Custom"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you that did work

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.