cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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 @Anonymous  ,  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
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors