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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.