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
Mat42
Helper III
Helper III

Convert Table Sections into Columns

The heading might be a bit misleading, but I can't really think of another way to put it.

 

I have a huge dataset, all housed on Sharepoint, that is horribly structured. It is comprised of hundreds of Excel spreadsheets (multiple tabs per file). Every sheet/page is uniform in design, but the data is set out for aesthetic, 'form filling' reasons rather than data reporting. This means that data transformation is a nightmare. I can't change the data collection process as that's a different department and out of my hands (though I have suggested alterations that could be made).

 

After multiple specific steps of 'Remove Alternate Rows' and Field Recording to capture single values that appear above banks of data, I've got it to a semi-structured point, but am now stuck.

 

Essentially, after I've pulled it apart and stuck it back together, the data I'm stuck with looks a bit like this (the below is not representative of the collected data, just the structure):

 

Column1Column2Column3Column4Column5Column6Column7Column8
NamenullnullAgenullGendernullnull
Johnnullnull34nullMalenullnull
Jennynullnull35nullFemalenullnull
Davenullnull21nullMalenullnull
Pollynullnull28nullFemalenullnull
DepartmentsBuilding No.nullnullPostcodenullNo. of Staffnull
IT1nullnullPP1 1PPnull14null
Finance2nullnullQQ3 3QQnull12null
Health3nullnullTT7 7TTnull5null
VehiclesNo.nullVehicle CostsnullnullnullBudget Code
Transit Van3null£2500nullnullnullBC1234
Car5null£1200nullnullnullBC4567

 

The problem is that the files have merged cells which PBI doesn't like.

 

As this data all pertains to a specific business name which was gathered using the aforementioned Field Recording, I need to take the blocks of data containing Departments and Vehicles and convert them to columns so they sit alongside the top data block (Names). I can then delete blank columns, lift first row entries to columns headers, and wind up with something like this:

 

NameAgeGenderDepartmentsBuilding No.PostcodeNo. of StaffVehicles TypeVehicle No.Vehicle CostsBudget Code
John34MaleIT1PP1 1PP14Transit Van3£2,500BC1234
Jenny35FemaleFinance2QQ3 3QQ12Car5£1,200BC4567
Dave21MaleHealth3TT7 7TT5nullnullnullnull
Polly28Femalenullnullnullnullnullnullnullnull
Polly28Femalenullnullnullnullnullnullnullnull

 

This I can then work with. 

 

Thanks to the lovely people on here teaching me how (specifically @parry2k), I'm applying the same coding to hundreds of files from a folder, which'll take ages, but will do the job in a single refresh.

 

Any ideas? I feel like I'm missing something obvious.

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Mat42 ,

 

According to your needs, you can achieve the results you expect in Power Query.

I did the following test, which can be used as a reference: "Reference" a new table in the query, and then do the following steps

v-henryk-mstf_0-1613111119085.png

v-henryk-mstf_1-1613111138019.png

Then create the index column and merge the table through the index column.

v-henryk-mstf_2-1613113772744.png

Finally put the corresponding lot on the table visual to get the desired result

v-henryk-mstf_3-1613114196421.png

Here is a relative link for referene:Solved: Filter rows in Query editor - Microsoft Power BI Community

Here is the sample pbix file.


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

View solution in original post

6 REPLIES 6
Mat42
Helper III
Helper III

Thanks guys. All fixed and sorted.

 

One day I'll get to grips with this system.

Hi @Mat42 ,

 

I am honored to be able to help you.

 

Best Regards,
Henry

v-henryk-mstf
Community Support
Community Support

Hi @Mat42 ,

 

According to your needs, you can achieve the results you expect in Power Query.

I did the following test, which can be used as a reference: "Reference" a new table in the query, and then do the following steps

v-henryk-mstf_0-1613111119085.png

v-henryk-mstf_1-1613111138019.png

Then create the index column and merge the table through the index column.

v-henryk-mstf_2-1613113772744.png

Finally put the corresponding lot on the table visual to get the desired result

v-henryk-mstf_3-1613114196421.png

Here is a relative link for referene:Solved: Filter rows in Query editor - Microsoft Power BI Community

Here is the sample pbix file.


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

parry2k
Super User
Super User

@Mat42 I think I got the gist. The solution is attached, basically, I'm taking 3 blocks into separate tables and merging those together. if for some reason, performance is an issue because of merging, we can completely ignore it and create a relationship between tables but let's start with this. Test it and let me know if this is what you are looking for.

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Mat42 so the data is always in these block:

 

For example:

 

1st block -> user 10 rows

2nd block -> company 3 rows 

3rd block -> vehicle 8 rows

 

so you will take a first come first serve row from company and vehicle and link with the user, correct? so first 3 rows of users will have company data and the rest 7 no company data because there are only 3 company rows and then the first 8 rows of users will have vehicle data and the remaining 2 will not have vehicle data since the vehicle block has only 8 rows. Is this correct understanding?

 

Now another question, what happens if the company or vehicle rows are more than user rows, does those rows get ignored?

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I've been trying to reply with further examples, but the system won't let me and keeps crashing out when I try.

 

The 3 blocks: Name, Department, and Vehicles are limited. There are 30 rows in the Name block, 10 rows in the Department block, and 10 rows in the Vehicles block. These are the maximum that can be entered for each block. I removed the blank rows for each block.

 

This means that a maximum of 30 names can be entered, 10 departments, and 10 vehicles. The number of each will change on each sheet, but will never exceed the maximum for each block.

 

In the previous example there were 5 names. This left 25 blank rows in the Names block. There were 3 departments, which left 7 blank rows in the Departments block. There were 2 vehicles, which left 8 blank rows in the Vehicles block.

 

Does that make sense?

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.