Forum Discussion
Raw Data Transforming
Hi,
I was given a set of raw data that i need to re arrange, so i can make better use of it in Power BI.
The raw data looks like this
| Client | Campus | Program | DPE | CLUSTER | NOV 1 6PM | NOV 1 8PM | NOV 1 10PM | NOV 1 11PM | NOV 2 1AM | NOV 2 3 AM | NOV 2 4AM | NOV 2 6AM | NOV 2 8AM | NOV 2 10AM | NOV 2 12PM |
| Alpha | PA | Guava | Ken | A | |||||||||||
| Beta | GA | Cherry | Ryu | A |
Is there a way i can move those November intervals into a single column when im in Power Query?
I was hoping to get this result so i can manage it better in BI
| Client | Campus | Program | DPE | CLUSTER | Interval | AR% |
| Alpha | PA | Guava | Ken | A | NOV 1 6PM | |
| Alpha | PA | Guava | Ken | A | NOV 1 8PM | |
| Alpha | PA | Guava | Ken | A | NOV 1 10PM | |
| Alpha | PA | Guava | Ken | A | NOV 1 11PM | |
| Alpha | PA | Guava | Ken | A | NOV 2 1AM | |
| Alpha | PA | Guava | Ken | A | NOV 2 3 AM | |
| Alpha | PA | Guava | Ken | A | NOV 2 4AM |
Lobs
In Power Query, you can select all the columns from Client up to Cluster and right-click, select UnPivot Other Columns, you will the desired layout.
Paste the following code in Blank query and checklet Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcswpyEhU0lEKcAQS7qWJZSCOd2oekASJEECxOtFKTqklID3uIOXOGalFRZVARlBlKZEmxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Client = _t, Campus = _t, Program = _t, DPE = _t, #"CLUSTER " = _t, #"NOV 1 6PM" = _t, #"NOV 1 8PM" = _t, #"NOV 1 10PM" = _t, #"NOV 1 11PM" = _t, #"NOV 2 1AM" = _t, #"01-11-02 3:00" = _t, #"NOV 2 4AM" = _t, #"NOV 2 6AM" = _t, #"NOV 2 8AM" = _t, #"NOV 2 10AM" = _t, #"NOV 2 12PM" = _t]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Client", "Campus", "Program", "DPE", "CLUSTER "}, "Attribute", "Value") in #"Unpivoted Other Columns"________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂
I guess you are seeing blank because you dont have data
I am not sure whether you want blanks in the final output, but you can try like this
let Source = Excel.Workbook(File.Contents("C:\Users\...\Sample.xlsx"), null, true), Sheet2_Sheet = Source{[Item="Sheet2",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet2_Sheet, [PromoteAllScalars=true]), #"Replaced Value" = Table.ReplaceValue(#"Promoted Headers",null,"zzz",Replacer.ReplaceValue,{"NOV 1 6PM", "NOV 1 8PM", "NOV 1 10PM", "NOV 1 11PM", "NOV 2 1AM", "NOV 2 3 AM", "NOV 2 4AM", "NOV 2 6AM", "NOV 2 8AM", "NOV 2 10AM", "NOV 2 12PM"}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Replaced Value", {"Client", "Campus", "Program", "DPE", "CLUSTER "}, "Attribute", "Value"), #"Replaced Value1" = Table.ReplaceValue(#"Unpivoted Other Columns","zzz","",Replacer.ReplaceText,{"Value"}) in #"Replaced Value1"you see the output as
8 Replies
- FowmySuper User
Lobs
In Power Query, you can select all the columns from Client up to Cluster and right-click, select UnPivot Other Columns, you will the desired layout.
Paste the following code in Blank query and checklet Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcswpyEhU0lEKcAQS7qWJZSCOd2oekASJEECxOtFKTqklID3uIOXOGalFRZVARlBlKZEmxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Client = _t, Campus = _t, Program = _t, DPE = _t, #"CLUSTER " = _t, #"NOV 1 6PM" = _t, #"NOV 1 8PM" = _t, #"NOV 1 10PM" = _t, #"NOV 1 11PM" = _t, #"NOV 2 1AM" = _t, #"01-11-02 3:00" = _t, #"NOV 2 4AM" = _t, #"NOV 2 6AM" = _t, #"NOV 2 8AM" = _t, #"NOV 2 10AM" = _t, #"NOV 2 12PM" = _t]), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Client", "Campus", "Program", "DPE", "CLUSTER "}, "Attribute", "Value") in #"Unpivoted Other Columns"________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂
- LobsHelper II
Hi Thanks for the quick response, the code worked, but when i tried it on my actual file, the table became empty.
Did i miss out on a code?
- FowmySuper User
Lobs
Click on the down arrow of any Column and click Ascending , you should see the data, it is sort of a bug.________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂