Forum Discussion

Lobs's avatar
Lobs
Helper II
5 years ago
Solved

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

 

                
ClientCampusProgramDPECLUSTER NOV 1 6PMNOV 1 8PMNOV 1 10PMNOV 1 11PMNOV 2 1AMNOV 2 3 AMNOV 2 4AMNOV 2 6AMNOV 2 8AMNOV 2 10AMNOV 2 12PM
AlphaPAGuavaKenA           
BetaGACherryRyuA           

 

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

 

ClientCampusProgramDPECLUSTER IntervalAR%
AlphaPAGuavaKenANOV 1 6PM 
AlphaPAGuavaKenANOV 1 8PM 
AlphaPAGuavaKenANOV 1 10PM 
AlphaPAGuavaKenANOV 1 11PM 
AlphaPAGuavaKenANOV 2 1AM 
AlphaPAGuavaKenANOV 2 3 AM 
AlphaPAGuavaKenANOV 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 check

    let
        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 🙂

    YouTube  LinkedIn

  • 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

  • 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 check

    let
        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 🙂

    YouTube  LinkedIn

    • Lobs's avatar
      Lobs
      Helper 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?

      • Fowmy's avatar
        Fowmy
        Super 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 🙂

        YouTube  LinkedIn