Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
AndrewPF
Helper V
Helper V

split, process and recombine data

I have some [anonymised] data - 10 rows in total - which looks like this: 

 

Employee IDFull NameEffective dateDepartmentPrev Row DepartmentPrev Row Effective datePrev Row End effective date
01John Smith30/06/2026N HouseH House13/03/202629/06/2026
02Jane Smith30/04/2026L HouseK Moore13/03/202629/04/2026
03Jessica Smith 31/03/2026M ViewB Cottage13/03/202630/03/2026
04Johnny Smith31/05/2026P ViewThe Parsley13/03/202630/05/2026
05Jezabel Smith31/05/2026A HouseE House13/03/202630/05/2026
06Jim Smith31/05/2026M ViewP Fold13/03/202630/05/2026
07Jake Smith30/04/2026A HouseR House13/03/202629/04/2026
08Jenny Smith31/05/2026D ViewP Fold14/03/202630/05/2026
09Jennifer Smith30/04/2026B FarmH House13/03/202629/04/2026
10Jackie Smith30/06/2026C HouseS View13/03/202629/06/2026

 

representing staff moves from one location to another. 

 

The "Department" therefore represents "Loaned To", and the "Prev Row Department" represents "Borrowed From". 

 

I need my final dataset to be 20 rows and look something like this: 

 

DepartmentFTE %
N House50
L House100
M View100
P View80
A House100
M View100
A House66
D View100
B Farm100
C House100
H House-50
K Moore-100
B Cottage-100
The Parsley-80
E House-100
P Fold-100
R House-66
P Fold-100
H House-100
S View-100

 

which I then need to summarise at home level (but that bit's easy). 

 

What's the best way of transposing the data? 

6 REPLIES 6
Poojara_D12
Super User
Super User

Hi @AndrewPF 

This isn’t actually a transpose problem—it’s about splitting each row into two records to represent movement in and out. The most effective way to handle it is in Power Query by creating two rows per original record: one for the “Loaned To” department (using the Department column with a positive FTE value) and one for the “Borrowed From” department (using Prev Row Department with a negative FTE value). You can do this either by duplicating the query and appending, or more efficiently by creating a list column that generates both records per row and then expanding it. This approach ensures you end up with the required 20 rows, correctly capturing inflow and outflow, and makes your final aggregation by department straightforward and accurate.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
v-nmadadi-msft
Community Support
Community Support

Hi @AndrewPF 

May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.


Thank you

v-nmadadi-msft
Community Support
Community Support

Hi @AndrewPF 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.


Thank you.

jgeddes
Super User
Super User

Your dataset is silent on the actual FTE values so I will make an assumption that the FTE values can be related to an employee via Employee ID and are available in an external table. 

With that assumption in place, you can get your desired result by selecting the 'Department', 'Prev Row Department', and 'Employee ID' columns and then unpivoting based on 'Department' and 'Prev Row Department'.

From there you can merge in the FTE values from the external table and then turn the 'Prev Row Department' rows negative.

 

Here is a sample code, 

let
    Source = 
    Table.FromRows(
        Json.Document(
            Binary.Decompress(
                Binary.FromText(
                    "hdJdb4IwFAbgv3LCtQmFgs5LP2aMHwuZizfGi6rH0Qg0Aczifv1aZmudxd215PDkPT1ns/FI4HW8mUgLWOW8TuWFEp90/ZCEXXl5g6k4VyhPU3MKqE+oLgj7pnrbkVyoOFbgHRfp6oVB5rAUonRykcVRxWFV8T37FUGRgfXHEtYcv+RhCCNR1+zzwVQJqGVG146Lyy2kFGNdn2jxI0VIWFlleHGZsWXGTc5vtsPMjQ5M56/uh/wrqm8znrs103QCE5Ed/rN6zVBOLUO5RXtvn7E9lJem2db3Gz+Gi56E6181fsTSHXAIE1bmz3fQyheQpt39iaN7qUeGWemorTu9/QE=", 
                    BinaryEncoding.Base64
                ), 
                Compression.Deflate
            )
        ), 
        let 
            _t = ((type nullable text) meta [Serialized.Text = true]) 
        in 
            type table [#"Employee ID" = _t, #"Full Name" = _t, #"Effective date" = _t, Department = _t, #"Prev Row Department" = _t, #"Prev Row Effective date" = _t, #"Prev Row End effective date" = _t]
    ),
    initial_type_set = 
    Table.TransformColumnTypes(
        Source,
        {
            {"Employee ID", Int64.Type}, {"Full Name", type text}, {"Effective date", type text}, {"Department", type text}, {"Prev Row Department", type text}, {"Prev Row Effective date", type text}, {"Prev Row End effective date", type text}
        }
    ),
    unpivot_selected = 
    Table.Unpivot(
        Table.SelectColumns(
            initial_type_set, 
            {"Department", "Prev Row Department", "Employee ID"}
        ), 
        {"Department", "Prev Row Department"}, 
        "Attribute", 
        "Value"
    ),
    merge_fte = 
    Table.NestedJoin(
        unpivot_selected, 
        {"Employee ID"}, 
        fteTable, 
        {"Employee ID"}, 
        "fteTable", 
        JoinKind.LeftOuter
    ),
    expand_fte = 
    Table.ExpandTableColumn(
        merge_fte, 
        "fteTable", 
        {"FTE"}, 
        {"FTE"}
    ),
    set_negatives = 
    Table.ReplaceValue(
        expand_fte, 
        each [FTE], 
        each 
            if [Attribute] = "Prev Row Department" 
                then -[FTE] 
                else [FTE], 
        Replacer.ReplaceValue, 
        {"FTE"}
    ),
    remove_columns = 
    Table.RemoveColumns(
        set_negatives,
        {"Employee ID", "Attribute"}
    ),
    final_type_set = 
    Table.TransformColumnTypes(
        remove_columns,
        {
            {"FTE", type number}
        }
    ),
    group_rows = 
    Table.Group(
        final_type_set, 
        {"Value"}, 
        {
            {"FTE", each List.Sum([FTE]), type nullable number}
        }
    ),
    rename_value = 
    Table.RenameColumns(
        group_rows,
        {
            {"Value", "Department"}
        }
    )
in
    rename_value

 

I used the following code to create FTE values based on the example data you provided.

let
    Source = 
    #table(
        type table [#"Employee ID"=nullable number, FTE=nullable number],
        {
            {1,.5},
            {2,1},
            {3,1},
            {4,.8},
            {5,1},
            {6,1},
            {7,.66},
            {8,1},
            {9,1},
            {10,1}
        }
    )
in
    Source

 

To end up with the result. (Note: I grouped by 'Department', summing the FTE.)

jgeddes_0-1774617621274.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





AndrewPF
Helper V
Helper V

When a member of staff (temporarily) moves from place A to place B, that represents "loaned to", or minus, from place A and a "borrowed from", or plus, in place B.  Therefore, if that staff member is on a part-time contract, and has an FTE of 80% of standard then, in the summary, place A would be 0.80 (80%) down, and place B would be 0.80 (80%) up. 

AnkitKukreja
Super User
Super User

Hi! @AndrewPF 

 

You might have to share your logic around it? How are you coming to the expected numbers so I can have a look at it.

 

 

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.