cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jbwilson1120
New Member

Table.TransformColumns - repeat rows n times and add a new column with 1 to n

Hello,

 

I have a revenue table that shows the total contract value, the start month, and the number of months (Term__c). I have been able to repeat the rows for the number of months, but I need to add a new column showing the number of months incrementing from 1 to Number of months. Here's what my data looks like:

2018-11-01 12_20_27-Backlog Dashboard 2 - Power Query Editor.png

 

I'd like to get to this, with MonthNumber being the new column. I'd like to keep the original Term__c column to see the total months.

2018-11-01 12_23_30-Book1 - Excel.png

 

I'm using this, but I'm not sure how to reference the Term__c in the List.Numbers to generate 1 to N.

Table.TransformColumns(#"Filtered Rows", {"Term__c", each List.Numbers(1,_,0), type list})

I've tried this but it errors out:

Table.TransformColumns(#"Filtered Rows", {"Term__c", each List.Numbers(1,"Term__c",0), type list})

And this:

Table.TransformColumns(#"Filtered Rows", {"Term__c", each List.Numbers(1,[Term__c],0), type list})

Any suggestions?

 

Thank you in advance.

1 ACCEPTED SOLUTION
jbwilson1120
New Member

I figured it out myself. I added a custom colum that copied the Term__c so that I had the original total months, then modified the TransformColumns step to this. The key was to drop the 3rd increment argument and use underscore as the second argument. TIL that underscore is a reference to the loop field when using each this way.

 

Table.TransformColumns(#"Filtered Rows", {"Term__c", each List.Numbers(1,_), type list})

View solution in original post

5 REPLIES 5
jbwilson1120
New Member

I figured it out myself. I added a custom colum that copied the Term__c so that I had the original total months, then modified the TransformColumns step to this. The key was to drop the 3rd increment argument and use underscore as the second argument. TIL that underscore is a reference to the loop field when using each this way.

 

Table.TransformColumns(#"Filtered Rows", {"Term__c", each List.Numbers(1,_), type list})

I'm not sure how the item listed in the solution actually gets you to the repeated rows. For me it just makes a column with a list type. This is what worked for me.

 

= Table.ExpandListColumn(Table.AddColumn(#"Filtered Rows", "MonthNumber", each List.Numbers(1,[Term__c])),"MonthNumber")

 

Ideal, thanks Tony

Hi @jbwilson1120  ,  can I ask how you managed to repeat the rows by the number of months please, i'm really stuck on this one?

 

Thank you

watch this video, it was really helpful for me: https://www.youtube.com/watch?v=6NAQf9b5J14

Helpful resources

Announcements
November 2022 Update

Check it Out!

Click here to read more about the November 2022 updates!

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power BI Dev Camp Session 27

Ted's Dev Camp

This session walks through creating a new Azure AD B2C tenant and configuring it with user flows and custom policies.