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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Debround
Frequent Visitor

Shaping data - get column headers in rows, when there are existing row headers

Hello,

 

I hope I can explain myself in an understandable way. I've got a table like the one below to record the number of hours worked on different projects.

 

   JanuaryJanuaryFebruaryFebruaryMarchMarchAprilAprilMayMayJuneJuneJulyJulyAugustAugustSeptemberSeptemberOctoberOctoberNovemberNovemberDecemberDecember
Year ProjectRoleOffice 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2Office 1Office 2
2010ColumbiaManager3 2   1 13 3 1 2 2 1 1 3
2010EndevourTechnician 51 5939 98 541312 2 2 1 
2011EndevourManager3 2   1 13 3 1 2 2 1 1 3
2011DiscoveryTechnician 51 5939 98 541312 2 2 1 

 

Obviously, the original one has a lot more of years, projects, and roles, but has the same months and offices (2 split in months). This format was quite convenient at the time it was created, as it was printed directly. But what I want now is to transform all these years of Excels, in just a table like the following; where I've got just the data I need, shaped in a way I can easily represent and filter it.

YearProjectRoleMonthOfficeHours
2010ColumbiaManagerJanuary13
2010ColumbiaManagerFebruary12
2010ColumbiaManagerApril11
2010EndevourTechnicianJanuary25
2010EndevourTechnicianFebruary11
2010EndevourTechnicianMarch15

 

I've tried transpose and other commands either in Excel or Power Query, without the desired result. I'll appreciate any help regarding this matter, thanks in advance.

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User
4 REPLIES 4
HotChilli
Super User
Super User

Thanks, @HotChilli and @C4YNelis for your responses.

 

It's a one-off, but I have to say that the custom function attracted me more, and it's faster!

@HotChilli The unpivot function is definitely the best way if you do insist on using Power BI to tackle this problem (and a great function to know anyhow).

 

However, imho, if it's just a one time transformation only (and this is especially true if you are planning on using this same data more often in the future), I believe it's better to just clean the structure of your source data as much as possible (if you have that opportunity), rather than use heavy queries to do so repeatedly for every refresh in the future. It's kind of like killing a mosquito with a cannon.

 

Just my two cents. 🙂

C4YNelis
Advocate II
Advocate II

Hi @Debround,

 

there are actually a lot of ways you could "easily" do this in Excel (I understand you need this table transformed just once)? In that case I wouldn't worry too much about formula's and complex ways.

 

If you have only twenty-four columns with months and offices, the easiest way I see is to actually copy your data in twelve or thirteen (depending on your final desired result) copy-paste actions to a new table on a different sheet. Just copy each month (including the first columns with years, projects and roles) with both offices to a new target sheet and in your sourcefile (I strongly recommend you make a backup of this file before you start), you delete the two columns with the offices for the first month that you copied (so that would be the column for January (Office 1 and 2). After this, you copy your data again, paste it below the previous set (which had two columns more on the right side) and again, you delete one month (two columns) on the left in your sourcefile (February (Office 1 and 2)). Continue this until you have copied your last set.

 

In the end you can deside whether you want the offices next to each other in separate columns, or that you make an additional column (e.g. titled "Office") where you copy your value (office 1 or office 2). If that's what you want, you'll need to copy one last time, and manually add the values for that last column (office names).

 

After you are done, you should have a target file that looks somewhat like a triangle upside down. Now delete all the additional month / office columns on the right side (except for the ones on the left that you wish to keep) and you're good to go.

 

If you do it the right way, I'm pretty sure it's a faster method than doing this any automated way (as long as it's a one-time thing).

 

Good luck!

 

Cheers,

Niels

 

(edited, because I just realized I made a little mistake in my explanation, not accounting for two columns per month.)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.