Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Shaping data for leave projection

Hi everyone and happy new year!

I'm working on a report for projected leave balances for employees. The data that comes from our payroll system is in this format:

Date15/01/202329/01/202312/02/202326/02/202312/03/202326/03/202309/04/202323/04/2023
Person A5059.20568.4177.61586.827079.20588.41
Person B2736.20545.4154.61563.825564.20573.41
Person C5867.20576.4185.61594.8295104.205113.41
Person D2231.20540.4149.61558.826877.20586.41
Person E716.20525.4134.61543.824049.20558.41

 

When I try to load it to Power BI the fields display like this: 

I'm guessing it needs to be in this kind of format: 

15/01/2023Person A50
15/01/2023Person B27
15/01/2023Person C58
15/01/2023Person D22
15/01/2023Person E7
29/01/2023Person A59.205
29/01/2023Person B36.205
29/01/2023Person C67.205
29/01/2023Person D31.205
29/01/2023Person E16.205

 

In practice there are significantly more staff than this and I want to do a projection for up to 1 year so it's not practical to do this manually every time, and I'd like other people in future to be able to just add the excel file with the raw data to the source folder without having to muck around with the spreadsheet. 

 

I want to produce a report that shows leave balances over time e.g. 

 

How would I go about doing this? Alternatively is there a quick way in excel to change the format to the second example above that I could use? 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous 

    You can put the follwing code to "Advanced Editor" in power query and you need to change your dateformat like:"mm/dd/yyyy"

    e.g: 2/28/2023

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XZA5DgMhDEWvEk09QizeKLP16UdTpk2k5P5S8NhOQQPYPD382bbl8fx836/TeVkXzLr0VDOOA0mCMnbmREUbQkmqNhTjwOTA9vVvuoxm5bE0cgTQTAhuomYmPApwjNtkuioiinAgZCZBN3UwU9ei5FCVMrtuOpWSrcRU2VzQ3YViLhJL7floMt31Vt+IeNXjtYgHHg+y6Q1D+6j9Bw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"01/15/2023" = _t, #"01/29/2023" = _t, #"02/12/2023" = _t, #"02/26/2023" = _t, #"3/12/2023" = _t, #"3/26/2023" = _t, #"4/9/2023" = _t, #"4/23/2023" = _t]),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Date"}, "Attribute", "Value"),
        #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Attribute", type date}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Date", "Person"}, {"Attribute", "Date"}}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Value", type number}})
    in
        #"Changed Type1"

    Output:

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

4 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Amine,

      Thanks for your reply. I want to do basically the reverse of this:  

       

       

      • grandtotal's avatar
        grandtotal
        Resolver III

        You can paste this to PowerQuery Advanced editor:

         

        let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XZA5DgMhDEWvEk09QizeKLP16UdTpk2k5P5S8NhOQQPYPD382bbl8fx836/TeVkXzLr0VDOOA0mCMnbmREUbQkmqNhTjwOTA9vVvuoxm5bE0cgTQTAhuomYmPApwjNtkuioiinAgZCZBN3UwU9ei5FCVMrtuOpWSrcRU2VzQ3YViLhJL7floMt31Vt+IeNXjtYgHHg+y6Q1D+6j9Bw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"15/01/2023" = _t, #"29/01/2023" = _t, #"12/02/2023" = _t, #"26/02/2023" = _t, #"12/03/2023" = _t, #"26/03/2023" = _t, #"09/04/2023" = _t, #"23/04/2023" = _t]),
        #"Renamed Columns" = Table.RenameColumns(Source,{{"Date", "Person"}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Person"}, "Date", "Value"),
        #"Changed Type with Locale" = Table.TransformColumnTypes(#"Unpivoted Other Columns", {{"Date", type date}}, "en-GB"),
        #"Changed Type with Locale1" = Table.TransformColumnTypes(#"Changed Type with Locale", {{"Value", type number}}, "en-GB")
        in
        #"Changed Type with Locale1"

         

        This is Unpivot other columns.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

    You can put the follwing code to "Advanced Editor" in power query and you need to change your dateformat like:"mm/dd/yyyy"

    e.g: 2/28/2023

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XZA5DgMhDEWvEk09QizeKLP16UdTpk2k5P5S8NhOQQPYPD382bbl8fx836/TeVkXzLr0VDOOA0mCMnbmREUbQkmqNhTjwOTA9vVvuoxm5bE0cgTQTAhuomYmPApwjNtkuioiinAgZCZBN3UwU9ei5FCVMrtuOpWSrcRU2VzQ3YViLhJL7floMt31Vt+IeNXjtYgHHg+y6Q1D+6j9Bw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"01/15/2023" = _t, #"01/29/2023" = _t, #"02/12/2023" = _t, #"02/26/2023" = _t, #"3/12/2023" = _t, #"3/26/2023" = _t, #"4/9/2023" = _t, #"4/23/2023" = _t]),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Date"}, "Attribute", "Value"),
        #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Attribute", type date}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Date", "Person"}, {"Attribute", "Date"}}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Value", type number}})
    in
        #"Changed Type1"

    Output:

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.