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
tusmo
Frequent Visitor

Help with a certain type of data transformation

I have only worked with Power BI for a couple weeks now, but I've noticed a certain pattern of data transformation I need to do repeatedly. For example I might have time series data with columns: Date | Sales of product A in region X | Sales of product A in region Y | Sales of product B in region X | Sales of product B in region Y. Now I want to visualize sales accross different product types and regions. In order to do that I transform the data into the following form: Date | Product | Region | Sales, now I can easily create interactive visualizations. However, as the number of differerent labels, in this case products and regions, increases doing this manually in the Query editor becomes tedious. Is there a way to easily do this within Power BI? I did write a Python script to do this for me but that's an additional step in the workflow I'd rather get rid off.

1 ACCEPTED SOLUTION

@tusmo

 

You can do Edit Queries, Select your Date column, right click and do Unpivot Other Columns.

This will give you Date column, Attribute Column and Value Column. You can rename Attribute and Value as required.

After this, select Attribute column, go to Add Column, use Column from Examples, create 2 columns for Color and Country.

 

Regards

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Would need an example of your source data and desired output. Can't really visualize your manual steps. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you for you answer, I'm sorry if my description of the problem was inadequate. Lets say that for example I have data that looks like this:

data1.png

 , and I want to create a chart where you can interactively visualize the data like this:

sales.png

 

 

So what I need to do is to transform the data into the following form:

 

data2.png

 

 

My question is, what would be the easiest way to do this transformation within Power BI for some arbitrary numbers of paint colors and countries? The way I'm doing it right now is by manually duplicating the original table, deleting all but one row, for example "Sales of red paint in Germany" and then adding custom columns "Red" and "Germany" and then appending the tables.

 

 

 

 

@tusmo

 

You can do Edit Queries, Select your Date column, right click and do Unpivot Other Columns.

This will give you Date column, Attribute Column and Value Column. You can rename Attribute and Value as required.

After this, select Attribute column, go to Add Column, use Column from Examples, create 2 columns for Color and Country.

 

Regards

This works great! I'm new working with data in general so I wasn't familiar with the concept of pivoting and I didn't know of the "Column from examples" function, it seems extremely useful. The data I'm working with is formatted nicely enough that I can also use "split column - by delimiter" to achieve this even more easily.

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.