Hello, I'm trying to set-up a power query to transform my data ready to pivot. My starting table has data in this shape/layout:
...and I'm trying to get into into a format that will allow me to generate a a pivot table that will be in this format:
i.e. I want to group by 'Category' and then by 'Question' and count the 'Answer' responses. I have thousands of rows and 58x Question, Question Category and Answer and the fields are not contiguous. It seems to me that I need to find a way to first stack the entries in all the fields ending 'Category', and 'Answer', but I'm struggling to know how to start?
Here is a mock-up of the starting table:
(cross-posted on the MS powerbi forum)
User | Q1Question | Q1Category | Q1Answer | Q2Question | Q2Category | Q2Answer | Q3Question | Q3Category | Q3Answer | Q4Question | Q4Category | Q4Answer | Q58Question | Q58Category | Q58Answer |
User 1 | Age? | Physical | High | Height? | Physical | Low | Shoe Size? | Physical | Medium | Preferred food? | Preference | High | Preferred Colour? | Preference | High |
User 2 | Age? | Physical | High | Height? | Physical | High | Shoe Size? | Physical | Medium | Preferred food? | Preference | Low | Preferred Colour? | Preference | Low |
User 3 | Age? | Physical | Medium | Height? | Physical | High | Shoe Size? | Physical | Medium | Preferred food? | Preference | Low | Preferred Colour? | Preference | Low |
User 4 | Age? | Physical | Medium | Height? | Physical | High | Shoe Size? | Physical | High | Preferred food? | Preference | Low | Preferred Colour? | Preference | Medium |
User 5 | Age? | Physical | Medium | Height? | Physical | High | Shoe Size? | Physical | High | Preferred food? | Preference | Medium | Preferred Colour? | Preference | Medium |
User 6 | Age? | Physical | Low | Height? | Physical | Medium | Shoe Size? | Physical | Low | Preferred food? | Preference | Low | Preferred Colour? | Preference | Medium |
...and I'm trying to get into into a format that will allow me to generate a a pivot table that will be in this format:
Final Output (Excel pivot table) | |||
High | Medium | Low | |
Physical | |||
Age? | 2 | 3 | 1 |
Height? | 4 | 1 | 1 |
Shoe Size? | 2 | 3 | 1 |
Preference | |||
Preferred food? | 1 | 1 | 4 |
Preferred Colour? | 1 | 3 | 2 |
i.e. I want to group by 'Category' and then by 'Question' and count the 'Answer' responses. I have thousands of rows and 58x Question, Question Category and Answer and the fields are not contiguous. It seems to me that I need to find a way to first stack the entries in all the fields ending 'Category', and 'Answer', but I'm struggling to know how to start?
Here is a mock-up of the starting table:
Power Query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi1OLVIwVNJRckxPtQdSARmVxZnJiTlApkdmegaISgXSJWhyPvnlQDI4Iz9VITizCl2nb2pKZmkuSKwoNS21qCg1RSEtPz/FHi6SmpecirABoco5Pye/tAi7ulgdqGuNSHYtVI5S50I8TdC1IGVwxxpjdSzcxsHmXBPqOxcjkilxLNQlcPeaDpR7sUQCkU42w+pkiP+xuhduFS4Xo4cdNQI4FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, Q1Question = _t, Q1Category = _t, Q1Answer = _t, Q2Question = _t, Q2Category = _t, Q2Answer = _t, Q3Question = _t, Q3Category = _t, Q3Answer = _t, Q4Question = _t, Q4Category = _t, Q4Answer = _t, Q58Question = _t, Q58Category = _t, Q58Answer = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"User", type text}, {"Q1Question", type text}, {"Q1Category", type text}, {"Q1Answer", type text}, {"Q2Question", type text}, {"Q2Category", type text}, {"Q2Answer", type text}, {"Q3Question", type text}, {"Q3Category", type text}, {"Q3Answer", type text}, {"Q4Question", type text}, {"Q4Category", type text}, {"Q4Answer", type text}, {"Q58Question", type text}, {"Q58Category", type text}, {"Q58Answer", type text}})
in
#"Changed Type"
(cross-posted on the MS powerbi forum)