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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Jyaul1122
Frequent Visitor

Repeat Rows up to Month

Dear Friend,

 

i have two tables: Sales  Table.

Product NameSales
P110
P225

 

and month table:

DateMonth
1/31/2024Jan-24
2/29/2024Feb-24
3/31/2024Mar-24
4/30/2024Apr-24

 

i want to repeat all rows up to all month based on the month table..

Result table:

Product NameSalesMonth
P110Jan-24
P225Jan-24
P110Feb-24
P225Feb-24
P110Mar-24
P225Mar-24
P110Apr-24
P225Apr-24

 

How can i achieve in Power BI

1 ACCEPTED SOLUTION
Alex87
Solution Sage
Solution Sage

Hello @Jyaul1122 

You can do this in Power Query:

1. Add a custom column "Index" = 1 for both tables

2. Merge query as new 

3. Expand Month

 

SALES TABLE 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjBU0lEyNFCK1QGyjYBsI1Ol2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product Name" = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product Name", type text}, {"Sales", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Index", each 1),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Index", Int64.Type}})
in
    #"Changed Type1"
MONTH TABLE

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3NtQ3MjAyUdJR8krM0wUyYnWilYz0jSxhwm6pSTBhYyTVvolFMGETfWMDmLBjAUQ4FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"Month", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Index", each 1),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Index", Int64.Type}})
in
    #"Changed Type1"
MERGE

let
    Source = Table.NestedJoin(#"Sales Table", {"Index"}, MonthTable, {"Index"}, "MonthTable", JoinKind.LeftOuter),
    #"Expanded MonthTable" = Table.ExpandTableColumn(Source, "MonthTable", {"Month"}, {"Month"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded MonthTable",{"Index"})
in
    #"Removed Columns"

 

Alex87_0-1716216009997.png

 

If it answers your query, please mark my reply as the solution. Thanks!

View solution in original post

3 REPLIES 3
Jyaul1122
Frequent Visitor

Thanks for your reply. Both reply are working fine.

v-jialongy-msft
Community Support
Community Support

Your solution is great, @Alex87  Here I have another idea in mind, and I would like to share it for reference.

 

Hi @Jyaul1122 

 

You can merge the two tables using the following dax:

ResultTable = 
CROSSJOIN(
    'Sales Table',
    'Month Table'
)

 

This is the result you want:

vjialongymsft_0-1716257706421.png

 

 

 

 

 

Best Regards,

Jayleny

 

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

 

Alex87
Solution Sage
Solution Sage

Hello @Jyaul1122 

You can do this in Power Query:

1. Add a custom column "Index" = 1 for both tables

2. Merge query as new 

3. Expand Month

 

SALES TABLE 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjBU0lEyNFCK1QGyjYBsI1Ol2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product Name" = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product Name", type text}, {"Sales", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Index", each 1),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Index", Int64.Type}})
in
    #"Changed Type1"
MONTH TABLE

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3NtQ3MjAyUdJR8krM0wUyYnWilYz0jSxhwm6pSTBhYyTVvolFMGETfWMDmLBjAUQ4FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"Month", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Index", each 1),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Index", Int64.Type}})
in
    #"Changed Type1"
MERGE

let
    Source = Table.NestedJoin(#"Sales Table", {"Index"}, MonthTable, {"Index"}, "MonthTable", JoinKind.LeftOuter),
    #"Expanded MonthTable" = Table.ExpandTableColumn(Source, "MonthTable", {"Month"}, {"Month"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded MonthTable",{"Index"})
in
    #"Removed Columns"

 

Alex87_0-1716216009997.png

 

If it answers your query, please mark my reply as the solution. Thanks!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.