Forum Discussion
Need Help !!! Unpivot multiples columns are not success
Hi
try this M Code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8klNzM5LPLRASUfJCIid87NTwRxDEM8YiE2A2C0xrwSixtAAKmwKxMEFRZklqaiisTrRSi6JRVDVQOxbWgLUjdBsCLUpJKM0LyW1CGYVzDqv0szkVJigIRjHxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, Line = _t, #"Material Name" = _t, Quantity = _t, Row = _t, Pallets = _t, #"Material Name 1" = _t, #"Quantity 1" = _t, #"Row 1" = _t, #"Pallets 1" = _t, #"Material Name 2" = _t, #"Quantity 2" = _t, #"Row 2" = _t, #"Pallets 2" = _t]),
ChangedType = Table.TransformColumnTypes(
Source,
{
{"Name", type text},
{"Line", Int64.Type},
{"Material Name", type text},
{"Quantity", Int64.Type},
{"Row", Int64.Type},
{"Pallets", Int64.Type},
{"Material Name 1", type text},
{"Quantity 1", Int64.Type},
{"Row 1", Int64.Type},
{"Pallets 1", Int64.Type},
{"Material Name 2", type text},
{"Quantity 2", Int64.Type},
{"Row 2", Int64.Type},
{"Pallets 2", Int64.Type}
}
),
Rowcount = Table.RowCount(ChangedType),
Records =
List.Accumulate(
{ 0..Rowcount - 1 },
{},
(state, current) =>
let
Rec1 = Record.SelectFields( ChangedType{current}, {"Name", "Line", "Material Name", "Quantity", "Row", "Pallets"} ),
Rec2 = Record.RenameFields(
Record.SelectFields( ChangedType{current}, {"Name", "Line", "Material Name 1", "Quantity 1", "Row 1", "Pallets 1"} ),
{ {"Material Name 1", "Material Name"}, {"Quantity 1", "Quantity"}, {"Row 1", "Row"}, {"Pallets 1", "Pallets" } }
),
Rec3 = Record.RenameFields(
Record.SelectFields( ChangedType{current}, {"Name", "Line", "Material Name 2", "Quantity 2", "Row 2", "Pallets 2"} ),
{ {"Material Name 2", "Material Name"}, {"Quantity 2", "Quantity"}, {"Row 2", "Row"}, {"Pallets 2", "Pallets" } }
),
Combined = List.Combine( { {Rec1}, {Rec2}, {Rec3} } )
in
List.Combine( {state, Combined } )
),
Final = Table.FromRecords (
Records, type
table [
Name = Text.Type,
Line = Int64.Type,
#"Material Name" = Text.Type,
Quantity = Number.Type,
Row = Number.Type,
Pallets = Number.Type
]
)
in
Final
- Chanleakna1237 years ago
Post Prodigy
LivioLanzo Thanks you for your response,
i'm sorry , i have another tables which need to be done the same. but this M Code really not bring me quite understanding ,
Can you please show step by step ? or do i have to all M Code and edit the tables one by one ? it's a mess sorry .Can you guide me step by step how to do it ? Probably i can learn from it and next time no more asking.
thanks
- LivioLanzo7 years ago
Solution Sage
Chanleakna123 if your other tables follow the same structure / logic, all you need to change is the first step called Source and point it to your raw table
- Chanleakna1237 years ago
Post Prodigy
hi LivioLanzo sorry i have different source which is different template, i mean the column are more than that .
i tried using yours , but fail to get it once i input the other source.Can you help me to do step by step on this ? then i can learn from it too.
i'm new here in BI .
thanks you