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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
klehar
Helper V
Helper V

Expand a number in a cell to the number of rows

Hi,

 

I have a table

klehar_0-1630075259159.png

 

I want to expand the duration column such that if it is 10, then I should get 11 rows starting from 0 to 10 for my column period

If duration = 2 then my period column should have 3 rows 0,1,2

 

See expected output below.

IDDurationPeriod
ID101100
ID101101
ID101102
ID101103
ID101104
ID101105
ID101106
ID101107
ID101108
ID101109
ID1011010
ID10220
ID10221
ID10222
ID10330
ID10331
ID10332
ID10333

 

 

I want this in M code

 

1 ACCEPTED SOLUTION
Jakinta
Solution Sage
Solution Sage

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwVNJRMlWK1QGxjYBsIyjbGMg2h7JNgGxDpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Duration = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each {0..Number.From([Duration])}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in
    #"Expanded Custom"

View solution in original post

1 REPLY 1
Jakinta
Solution Sage
Solution Sage

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwVNJRMlWK1QGxjYBsIyjbGMg2h7JNgGxDpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Duration = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each {0..Number.From([Duration])}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
in
    #"Expanded Custom"

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors