cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
matherhorn64 Frequent Visitor
Frequent Visitor

Count number of times table was duplicated in Power Query

Hi All,

 

I have a certain table ("Table") in Power Query and I'm using Table.Repeat function duplicate it for X number of times (X is coming from another table). What I want to do is to add to the "Table" new column which would show what duplicatation sequence it is.

 

For example, in "Table" I have 100 rows and I want to duplicated it for 3 times, so this new column should show me "1" for rows 1-100, "2" for rows 101-200, "3" for rows 201-300.

 

Any ideas how to do it?

1 ACCEPTED SOLUTION

Accepted Solutions
MarcelBeug Super Contributor
Super Contributor

Re: Count number of times table was duplicated in Power Query

You can add a 0-based Index column, Integer-Divide the values by the number of rows of the original table and add 1.

 

let
    Source = Table1,
    Repeated = Table.Repeat(Source,Table.FirstValue(Table2)),
    #"Added Index" = Table.AddIndexColumn(Repeated, "Duplication", 0, 1),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Duplication", each 1 + Number.IntegerDivide(_, Table.RowCount(Source)), Int64.Type}})
in
    #"Integer-Divided Column"
Specializing in Power Query Formula Language (M)
2 REPLIES 2
MarcelBeug Super Contributor
Super Contributor

Re: Count number of times table was duplicated in Power Query

You can add a 0-based Index column, Integer-Divide the values by the number of rows of the original table and add 1.

 

let
    Source = Table1,
    Repeated = Table.Repeat(Source,Table.FirstValue(Table2)),
    #"Added Index" = Table.AddIndexColumn(Repeated, "Duplication", 0, 1),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Duplication", each 1 + Number.IntegerDivide(_, Table.RowCount(Source)), Int64.Type}})
in
    #"Integer-Divided Column"
Specializing in Power Query Formula Language (M)
matherhorn64 Frequent Visitor
Frequent Visitor

Re: Count number of times table was duplicated in Power Query

Wonderful, thanks again!

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 150 members 2,107 guests
Please welcome our newest community members: