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.
Hello,
I have a spreadsheet where the data is listed by "category rows", like the example below.
To use this data in Power BI I need it to look like the table below, where the category is transformed into its own column.
Is there a transformation I can apply that will automatically recognize these category rows and change them into a column, applying the right category label to each row?
This also needs to be dynamic, so if additional categories like "MEATS" or "BAKERY ITEMS" were added the transformation would automatically work for those as well.
Thank you for your help!
-Jenna
Solved! Go to Solution.
Assuming that, say, 2017 is always going to have data in except on your rows, you could try making a new column in the query editor that pulls through the column with fruits, vegetables etc in if 2017 is blank and leaves it blank otherwise. IIRC there's then an option to fill down, which should populate the new column with the category headers as needed. You can then filter out anything in 2017 that's blank and you should be there
You can try the following:
Insert new column index starting at 0. In Applied Steps, I renamed to 'AddIndex'.
= Table.AddIndexColumn(#"Changed Type", "Index", 0, 1)
Review the documentation at https://www.powerquery.training/portfolio/replicate-power-pivots-switch-function/ as it helped to define the possible variables separately from the next step.
Here is the fnSwitch( ) I made to start you off. This is really so you don't have to write a bunch of 'or' in the next add column.
(input) => let values = { {"FRUITS", "FRUITS"}, {"VEGETABLES", "VEGETABLES"}, {"BAKERY", "BAKERY"}, {"CHEESE", "CHEESE"} }, Result = List.First(List.Select(values, each _{0}=input)) {1} in Result
Add custom column 'Type'.
try if AddIndex[Column1] {[Index]} = fnSwitch([Column1]) then AddIndex[Column1] {[Index]} else null otherwise null
Filter 'Type' down
Filter one of the 'Year' columns null values out.
You should end up with:
Proud to be a Super User!
@ChrisMendoza I haven't had the chance to try this out yet, but would it work with additional categories beyond Fruits, Vegetables, Bakery and Cheese? I'd like this to be as hands-off as possible, so I don't need to manually edit something every time the categories are changed.
Thanks,
Jenna
The accepted solution is the most hands off if the null value is constant/consistent in your data.
Proud to be a Super User!
Assuming that, say, 2017 is always going to have data in except on your rows, you could try making a new column in the query editor that pulls through the column with fruits, vegetables etc in if 2017 is blank and leaves it blank otherwise. IIRC there's then an option to fill down, which should populate the new column with the category headers as needed. You can then filter out anything in 2017 that's blank and you should be there
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
115 | |
100 | |
90 | |
68 | |
61 |
User | Count |
---|---|
150 | |
120 | |
100 | |
87 | |
68 |