Forum Discussion
babuInba
4 years agoFrequent Visitor
Power query transpose one column and highlight matching rows
Hi Experts,
Requesting you to help with below output
current table
| Name | Dept | SHIFT | Access |
| Sample1 | A | DAY | 1 |
| Sample1 | A | DAY | 2 |
| Sample2 | B | NIGHT | 1 |
| Sample2 | B | NIGHT | 3 |
| Sample3 | C | DAY | 1 |
| Sample3 | C | DAY | 2 |
desired output
| Name | Dept | SHIFT | 1 | 2 | 3 |
| Sample1 | A | DAY | Yes | Yes | |
| Sample2 | B | NIGHT | Yes | Yes | |
| Sample3 | C | DAY | Yes | Yes |
NewStep= let a=Table.TransformColumns(PreviousStepName,{"Access",Text.From}) in Table.Pivot(a,List.Distinct(a[Access]),"Access","Access",each if _={} then null else "Yes")
2 Replies
- AnonymousNot applicable
Hi babuInba,
Go to the advanced editor in the view tab, delete what you have and copy this:
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Duplicated Column" = Table.DuplicateColumn(Source, "Name", "Name - Copy"), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Duplicated Column", {{"Access", type text}}, "es-ES"), List.Distinct(Table.TransformColumnTypes(#"Duplicated Column", {{"Access", type text}}, "es-ES")[Access]), "Access", "Name - Copy", List.Count), #"Changed Type" = Table.TransformColumnTypes(#"Pivoted Column",{{"1", type text}, {"2", type text}, {"3", type text}}), #"Replaced Value" = Table.ReplaceValue(#"Changed Type","1","Yes",Replacer.ReplaceText,{"1", "2", "3"}), #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","0","",Replacer.ReplaceText,{"1", "2", "3"}), #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"Name", type text}, {"Dept", type text}, {"SHIFT", type text}}) in #"Changed Type1"Probably you will have to change the source step.
- wdx223_DanielCommunity Champion
NewStep= let a=Table.TransformColumns(PreviousStepName,{"Access",Text.From}) in Table.Pivot(a,List.Distinct(a[Access]),"Access","Access",each if _={} then null else "Yes")