Forum Discussion
Transpose of table
- 7 years ago
Hi,
This M code works
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Name", type text}, {"Name 2", type text}, {"Date", type text}, {"Detail", type text}, {"Rank 1 ", Int64.Type}, {"Rank 2", Int64.Type}, {"Rank 3", Int64.Type}, {"Category", type text}, {"Movement", type text}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"), Partition = Table.Group(#"Unpivoted Other Columns", {"Index"}, {{"Partition", each Table.AddIndexColumn(_, "Index1",1,1), type table}}), #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Attribute", "Value", "Index1"}, {"Attribute", "Value", "Index1"}), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Partition", {{"Index", type text}}, "en-IN"), List.Distinct(Table.TransformColumnTypes(#"Expanded Partition", {{"Index", type text}}, "en-IN")[Index]), "Index", "Value"), #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index1"}) in #"Removed Columns"The only thing i cannot get to work here is the order of the items in the attribute column to match your order.
Hope this helps.
nirvana_moksh hope attached will do the job.
- nirvana_moksh7 years ago
Impactful Individual
parry2k - Thanks a lot for taking a stab at this! I did the same initially, and instead of joining to the ID column, in the main table I defined an Index Column which I utilized instead to connect to the other table wherein I did the unpivoting, but this is not working as expected on my end with my entire data set. Also worth mentioning my ID is not a distinct column and each ID might have multiple rows which is the reason I defined the index column. Any other suggestions if you may have?
- parry2k7 years ago
Super User
nirvana_moksh using index column make sense to bring unique id. So what exactly is not working on your dataset?
- nirvana_moksh7 years ago
Impactful Individual
parry2k - Using the index column for the relationship for some reason does not filter the secondary table correctly (clicking on a row on the main table shows up the "first value" of some other row). Just for the sake of it, I used the ID column and that worked, which I think is odd. In your opinion is the usage of an
parry2k wrote:nirvana_mokshusing index column make sense to bring unique id. So what exactly is not working on your dataset?
index column as a unique identifier a good approach? Because I do use the same logic for other solutions for dynamic axis change. When I check the index column id for one row on the main table and the same for the second it matches, but the value output is not correct for some reasonThank You