Forum Discussion
vincentakatoh
6 years agoHelper IV
Count Multiple Columns
Hi, Need help to count the part usage. Below is sample data, Case_Number PartNumber_Part replace_1st PartNumber_Part replace_2nd PartNumber_Part replace_3rd PartNumber_Part replace_4th P...
AlB
6 years agoCommunity Champion
You should unpivot the partNumber columns in the query editor
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0MDAwNDIGsvJKc3KwU7E60UpGcLUmKLogLFM4ywzOMgfrQ6ixIGQbSLkJFmtMcStHtVcBBcfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Case_Number = _t, #"PartNumber_Part replace_1st" = _t, #"PartNumber_Part replace_2nd" = _t, #"PartNumber_Part replace_3rd" = _t, #"PartNumber_Part replace_4th" = _t, #"PartNumber_Part replace_5th" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Case_Number", Int64.Type}, {"PartNumber_Part replace_1st", Int64.Type}, {"PartNumber_Part replace_2nd", Int64.Type}, {"PartNumber_Part replace_3rd", Int64.Type}, {"PartNumber_Part replace_4th", Int64.Type}, {"PartNumber_Part replace_5th", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Case_Number"}, "Attribute", "Value")
in
#"Unpivoted Columns"
to get something like this. Fromt that you ance get what you want easily:
Case_NumberAttributeValue
| 1 | PartNumber_Part replace_1st | 1000123 |
| 2 | PartNumber_Part replace_1st | 1000124 |
| 2 | PartNumber_Part replace_2nd | 1000123 |
| 2 | PartNumber_Part replace_3rd | 1000125 |
| 2 | PartNumber_Part replace_4th | 1000126 |
| 2 | PartNumber_Part replace_5th | 1000127 |
| 3 | PartNumber_Part replace_1st | 1000128 |
| 3 | PartNumber_Part replace_2nd | 1000123 |
| 4 | PartNumber_Part replace_1st | 1000124 |
| 4 | PartNumber_Part replace_2nd | 1000125 |
| 5 | PartNumber_Part replace_1st | 1000126 |
Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs
Cheers