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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Ackbar-Learner
Resolver I
Resolver I

How to generate new lines of data by subcategories

Hi I need help to do the following. I have the below two tables. What i need is that each line of the first table to repeat itself X times at each change in transaction date but the second table department data should come as a new column in the first table for each line. (X being being the number of lines in the second table)

 

AckbarLearner_0-1693122892951.png

 

AckbarLearner_1-1693122906254.png

For example, the first line in first table with date 01/07/2021 should repeat six times and each of the 6 lines should contain 1 department in a new column named Department.

 

Thank you in advance

 

1 ACCEPTED SOLUTION

or even simplier 

let
    Table1 = your_table1_name,
    Table2 = your_table2_name[Department],
    add_col = Table.AddColumn(Table1, "Department", each Table2),
    expand = Table.ExpandListColumn(add_col, "Department")
in
    expand

View solution in original post

5 REPLIES 5
AlienSx
Super User
Super User

Hi, @Ackbar-Learner 

    size = Table.RowCount(Table2),
    rows = Table.ToRows(Table1),
    txform = 
        List.Transform(
            rows,
            (x) => 
                [a = List.Repeat({x}, size),
                b = Table.FromColumns(Table.ToColumns(Table.FromRows(a)) & {Table2[Department]}, Table.ColumnNames(Table1) & {"Department"})][b]
        ),
    z = Table.Combine(txform)

Hi @AlienSx 

 

Thanks for your reply. I am a bit new to this M power query code. I was like following the applied steps in power query so that I am more at ease understanding what is happening to the data. So I am not sure where to insert the code you provided 😞 

 

Kindly advise


Thanks

@Ackbar-Learner create new (blank) query, run Advanced Editor and replace everything inside with this

let
    Table1 = your_table1_name,
    Table2 = your_table2_name,
    size = Table.RowCount(Table2),
    rows = Table.ToRows(Table1),
    txform = 
        List.Transform(
            rows,
            (x) => 
                [a = List.Repeat({x}, size),
                b = Table.FromColumns(Table.ToColumns(Table.FromRows(a)) & {Table2[Department]}, Table.ColumnNames(Table1) & {"Department"})][b]
        ),
    z = Table.Combine(txform)
in
    z

don't forget to replace your_table1_name and your_table2_name (2nd and 3rd rows of code) with the names of your tables/queries.  

or even simplier 

let
    Table1 = your_table1_name,
    Table2 = your_table2_name[Department],
    add_col = Table.AddColumn(Table1, "Department", each Table2),
    expand = Table.ExpandListColumn(add_col, "Department")
in
    expand

So easy in the end 🙂

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Kudoed Authors