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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rahkim
Helper I
Helper I

Transform data with multiple column headers and row headers

Greetings,

 

I have an excel sheet as my data source and the owner of this sheet arranged the data so that it has multiple column headers and a couple of row headers.  As a bonus, they made they made it so new data is added to columns and not rows.  I want to transpose and unpivot all this data.  It looks like this picture and it goes on to the right through December.  There are also several more locations.

 

rahkim_0-1711109751566.png

 

I tried transposing and unpivoting but the location column always seems to cause issues.  How can I get it to look like this in query?

 

rahkim_1-1711110317198.png

(I don't need the day of the week since I can use a date table for that join info.)

 

Here is a sample of the data.

 

LocationSupplier3/4/20243/4/20243/4/20243/5/20243/5/20243/5/2024
  MonMonMonTueTueTue
  1st2nd3rd1st2nd3rd
AtlantaSupplier 11%3% 1%3% 
 Supplier 22%3% 2%3% 
 Supplier 32%3%4%2%3%4%
 Supplier 42%3% 2%3% 
HoustonSupplier 35%6% 5%6% 
 Supplier 45%6% 5%6% 
 Supplier 55%6% 5%6% 
 Supplier 65%6%7%5%6%7%

 

Thanks!

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

The top row will add a suffix to each date field automatically (.1,.2)  if you use them as column headers so you can use that to your advantage.

Filter out the 2nd and 3rd rows above (Mon, Tues    1st, 2nd)

Then perform a Fill Down on Location (you'll need to get null values in the column to make that work).

Now do the Unpivot on all columns except the first 2.

There will be a few steps more but you can get help by searching the forum for Unpivot multiple columns.

View solution in original post

4 REPLIES 4
HotChilli
Super User
Super User

That's the point of my first sentence. When you unpivot, there will be a suffix on the date field which you can separate out to use as shift column

Unfortunately the suffixes are sequential so it was a bit tougher.  The first shifts were always just the date while the second and third shifts increased in number:

 

rahkim_0-1711365624636.png

 

So I split on the "_" to get this:

 

rahkim_1-1711365769934.png

 

Then I added a conditional column:

= Table.AddColumn(#"Renamed Columns1", "Custom", each if Number.Mod([Shift],2) = 0 then "3rd" else if [Shift] = null then "1st" else "2nd")

 

Which gave me the final results in:

 

rahkim_2-1711365854204.png

 

 

 

HotChilli
Super User
Super User

The top row will add a suffix to each date field automatically (.1,.2)  if you use them as column headers so you can use that to your advantage.

Filter out the 2nd and 3rd rows above (Mon, Tues    1st, 2nd)

Then perform a Fill Down on Location (you'll need to get null values in the column to make that work).

Now do the Unpivot on all columns except the first 2.

There will be a few steps more but you can get help by searching the forum for Unpivot multiple columns.

Hi @HotChilli .  Thanks for the reply.  

Why would I also remove the third row which has 1st, 2nd and 3rd?  I need those to know the shift.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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