Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
Only 6% of Analytics Reporting in organizations source their data from standard databases. Oh no, I made up that number. I have no idea what the numbers are. But I am certain that the majority of self-service BI & data analytics users must deal with a lot of crappy data.
One of the big issues Power Query users must also deal with is Table Structuring. When should you use “Transpose” and when should you use “Unpivot”?
(The data used in this demo is number 3 on the list of Dirty Data Samples on this link).
I have introduced the two concepts in part one of this article. Our data had the format shown below:
Order ID labelled “b” is well structured in a column, but Segment and Ship Mode are on Rows instead of columns as well.
So, we started by Transposing the table.
Then we did a little extra cleaning, removing the Total lines, Filling down the Segment Column. And the very important one, Promoted the first row to headings. This step was necessary to do a partial transpose (Unpivot) of all other columns apart from Segment and Ship Mode (which are now in order).
Then we could get a clean table (after naming the columns properly).
What we have cleverly done can be summarized as:
Apparently, our steps worked because we had only one good column before transpose. And after transposing, we could make that row a header row and unpivot the section of headings to bring it back. If we had two good columns before transpose, it means we would have those two columns go into rows after transpose. Only one can be made header, and only that same one can be Unpivoted back to column. This is the bone of contention in this article.
Have a look at the table below:
If we transpose this table, Ship Mode and Segment (a) will be well aligned as columns while Order ID and Order Date (b) will now be wrongly aligned as rows. That is back to square 1. We would be running in circles.
So, the approach must be different to solve this, and the following steps summarizes that:
I will conclude by stressing the fact that, when you require a Transpose step in your cleaning steps, you should:
Make sure the items you need to be partially transposed are sitting on the headers of your data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.