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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
pfInigo
Frequent Visitor

Convert a list of numbers into a another list

Hi,

 

I have a problem I can't figure out.

I have a table of numbers attributable to an ID, that I want split out based on the value in one of the columns (Count).

The following is what I have and what I want:

Current:   
IDOrderCountValue
1120.5
1211
1320
    
Desired:   
IDOrderCountValue
1110.5
1210.5
1311
1410
1510

 

Any help is much appreciated, thanks,

Paul

1 ACCEPTED SOLUTION

Thank you for this!

I used a very similar method to get my solution:

....

#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Sorted Rows2", {"fk_LayerId", "order", "value"}, "Attribute", "Value.1"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each Table.Repeat(Table.FromRecords({[Col1=1]}),[Value.1])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Col1"}, {"Col1"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Attribute", "Value.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Col1", "Count"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Count", Int64.Type}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Changed Type1",{"fk_LayerId", "order", "Count", "value"}),
    #"Grouped Rows" = Table.Group(#"Reordered Columns", {"fk_LayerId"}, {{"Rows", each _, type table [fk_LayerId=nullable number, order=nullable number, Count=nullable number, value=nullable number]}}),
    Indexed = Table.TransformColumns(#"Grouped Rows", {{"Rows", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}}),
    #"Expanded Rows" = Table.ExpandTableColumn(Indexed, "Rows", {"Count", "value", "GroupIndex"}, {"Count", "value", "GroupIndex"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Expanded Rows",{{"GroupIndex", Int64.Type}, {"Count", Int64.Type}, {"value", type number}}),
    #"Renamed Columns2" = Table.RenameColumns(#"Changed Type2",{{"GroupIndex", "order"}, {"Count", "count"}})
in
    #"Renamed Columns2"

 

as I needed the order (Index) to restart for each Id

 

 

View solution in original post

3 REPLIES 3
jgeddes
Super User
Super User

if @BA_Pete 's solution does not work for you I went a bit of a different direction.

I expanded upon your data to start with...

jgeddes_0-1670433228259.png

Did the following...

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAWMjIDbQM1WK1YmG8yFyMBFjKDYAi4DkTaDYCC5iCtWFUGMGNwskAtJvDrNNKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Order = _t, Count = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Order", Int64.Type}, {"Count", Int64.Type}, {"Value", type number}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Numbers(1,[Count],0)),
#"ExpandTableColumns" = Table.ExpandListColumn(#"Added Custom", "Custom"),
#"Removed Columns" = Table.RemoveColumns(ExpandTableColumns,{"Order", "Count"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Count"}}),
#"Added Index" = Table.AddIndexColumn(#"Renamed Columns", "Order", 1, 1, Int64.Type),
#"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"ID", "Order", "Count", "Value"})
in
#"Reordered Columns"

And ended up with... 

jgeddes_1-1670433322991.png

Cheers!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you for this!

I used a very similar method to get my solution:

....

#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Sorted Rows2", {"fk_LayerId", "order", "value"}, "Attribute", "Value.1"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each Table.Repeat(Table.FromRecords({[Col1=1]}),[Value.1])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Col1"}, {"Col1"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Attribute", "Value.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Col1", "Count"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Count", Int64.Type}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Changed Type1",{"fk_LayerId", "order", "Count", "value"}),
    #"Grouped Rows" = Table.Group(#"Reordered Columns", {"fk_LayerId"}, {{"Rows", each _, type table [fk_LayerId=nullable number, order=nullable number, Count=nullable number, value=nullable number]}}),
    Indexed = Table.TransformColumns(#"Grouped Rows", {{"Rows", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}}),
    #"Expanded Rows" = Table.ExpandTableColumn(Indexed, "Rows", {"Count", "value", "GroupIndex"}, {"Count", "value", "GroupIndex"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Expanded Rows",{{"GroupIndex", Int64.Type}, {"Count", Int64.Type}, {"value", type number}}),
    #"Renamed Columns2" = Table.RenameColumns(#"Changed Type2",{{"GroupIndex", "order"}, {"Count", "count"}})
in
    #"Renamed Columns2"

 

as I needed the order (Index) to restart for each Id

 

 

BA_Pete
Super User
Super User

Hi @pfInigo ,

 

Need a bit more info around what these fields represent and how dynamic this needs to be.

The easiest way to duplicate the rows [Count] times would be to add a new column with this:

= {1..[Count]}

...then expand this column.

Re-incrementing the [Order] column could be done by subsequently adding an Index column, and re-stating the [Count] column would just be a new column with ' = 1 ' as the calculation, but these options aren't dynamic.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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