Forum Discussion
Anonymous
6 years agoNot applicable
Convert data range to a mappable list
Hello fellows, I have a data table looks like this Sales 1:3 Cost 4 Tax 5:6 I want to convert them into: Sales 1 Sales 2 Sales 3 Cost 4 Tax 5 Tax 6 ...
- 6 years ago
Here's a (somewhat pedestrian) way of doing that in Power Query. I am sure there are more elegant solutions.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7MSS1W0lEytDJWitWJVnLOLy4Bck3AnJDECiDb1MpMKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Transaction Type" = _t, Range = _t]), #"Added Custom" = Table.AddColumn(Source, "Custom", each let d= Text.PositionOf([Range],":"), r= if d = -1 then List.Numbers(Number.FromText([Range]),1) else List.Numbers(Number.FromText(Text.Start([Range],d)),1+Number.FromText(Text.End([Range],Text.Length([Range])-d-1))-Number.FromText(Text.Start([Range],d))) in r ), #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom") in #"Expanded Custom" - 6 years ago
Anonymous it is pretty straight forward, start new blank query and click advanced editor and paste the following code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCk7MSS1W0lEytDJWitWJVnLOLy4Bck3AnJDECiDb1MpMKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type text}, {"B", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Pos", each Text.PositionOf([B],":")), #"Added Custom1" = Table.AddColumn(#"Added Custom", "List", each if [Pos]=-1 then {Number.FromText([B])} else {Number.FromText(Text.Middle([B],0,[Pos]))..Number.FromText(Text.Middle([B],[Pos]+1))}), #"Expanded List" = Table.ExpandListColumn(#"Added Custom1", "List"), #"Removed Columns" = Table.RemoveColumns(#"Expanded List",{"Pos"}) in #"Removed Columns". The main logic is in step #"Added Custom1"
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Anonymous
6 years agoNot applicable
I transfromed the table into
| min | max | |
| Sales | 1 | 3 |
| Cost | 4 | 4 |
| Tax | 5 | 6 |
Still not sure how can I use it to mapping though...