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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MStark
Helper III
Helper III

Stacking Columns

Our system exports employees that work double shifts on 1 line. I need help spliting the data and stacking it so each shift is a separate row. Can anyone help with this?

 

Export Data:

NamePositionWork DateSchedule FacilityScheduled DepartmentScheduled PositionScheduled ShiftScheduled UnitScheduled HoursX
John DoeCNA2/17/2023Test,TestNursing,NursingRep,Rep7a-3p,3p-7pSecond Floor,Float8.0,4.0
John DoeCNA2/18/2023TestNursingRep7a-3pSecond Floor8

 

I need the data stacked like this:

NamePositionWork DateSchedule FacilityScheduled DepartmentScheduled PositionScheduled ShiftScheduled UnitScheduled HoursX
John DoeCNA2/17/2023TestNursingRep7a-3pSecond Floor8
John DoeCNA2/18/2023TestNursingRep3p-7pFloat4
John DoeCNA2/18/2023TestNursingRep7a-3pSecond Floor8

 

Any advise?

 

Thanks in advance for your time!!

 

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

Here's a way to do it via the interface.

Duplicate the table twice (so that we can keep the original table as a .

In each copy we have 3 fixed columns and other columns containing related values i.e. all the values before the comma in each column need to be combined to make a row. All the values after the comma should be combined too.

So let's make each 'table copy' produce the rows we want before recombining afterwards .  We can do this by: (this describes the steps in each table copy)

1. Select the first 3 columns.

2. Unpivot other columns.

3. Split the Value column (on comma)

4. Remove the column we don't want in each table i.e. 'Table Copy1' - remove the column holding text before the comma (Value.1)
    'Table Copy2' - remove the column holding text after the comma (Value.2)

5. Rename the column left behind - 'Value'

6. Pivot the Attribute column, using Value in the Values section and 'Do not aggregate' in the advanced section.

7. Append the 2 tables together (this is now possible because both tables have the same structure)

---

There is an intermediate step in one of the table copies where the null entries in Value should be filtered out.  We don't need those rows so get rid of them before the Pivot.

--

See if you can work your way through that and get back to me if you are stuck.

View solution in original post

4 REPLIES 4
HotChilli
Super User
Super User

Here's a way to do it via the interface.

Duplicate the table twice (so that we can keep the original table as a .

In each copy we have 3 fixed columns and other columns containing related values i.e. all the values before the comma in each column need to be combined to make a row. All the values after the comma should be combined too.

So let's make each 'table copy' produce the rows we want before recombining afterwards .  We can do this by: (this describes the steps in each table copy)

1. Select the first 3 columns.

2. Unpivot other columns.

3. Split the Value column (on comma)

4. Remove the column we don't want in each table i.e. 'Table Copy1' - remove the column holding text before the comma (Value.1)
    'Table Copy2' - remove the column holding text after the comma (Value.2)

5. Rename the column left behind - 'Value'

6. Pivot the Attribute column, using Value in the Values section and 'Do not aggregate' in the advanced section.

7. Append the 2 tables together (this is now possible because both tables have the same structure)

---

There is an intermediate step in one of the table copies where the null entries in Value should be filtered out.  We don't need those rows so get rid of them before the Pivot.

--

See if you can work your way through that and get back to me if you are stuck.

This Worked! Amazing!

Really appreciate your Help! Thanks!!

HotChilli
Super User
Super User

Can you explain why the middle row in the desired table has a date of 18th? Is this what you want or is there an error there?

That is an error. It should be 2/17

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors