Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
LisanSpiegelaar
Regular Visitor

Creating table with categories from 2 columns in 1 column

Hi people,

 

I am creating a content performance report. My company posts content on LinkedIn, and assigns a domain to each article. However, one article can have multiple domains. In the datafile I got from the Marketing department, both domains are listed seperately in 2 columns. I want to add the performance of all articles that share the same domain, for which I have to look at two columns. 

 

So I have got a table that looks like this:

Post dateDomain 1Domain 2ViewsLikes
1-2-2022Work 105
1-3-2022Care 136
1-4-2022LivingCare149
1-5-2022WorkCare1611

 

What I want to create is this:

DomainNumber of articlesViewsLikes
Work22616
Care34326
Living1149

 

I have no clue how to do this... I have looked into DISTINCT(UNION(VALUES..., GROUPBY, SUMMARIZE... Nothing seems to work and I am out of ideas.

 

Help would be very much appreciated! Thanks!

1 ACCEPTED SOLUTION

Unpivoting as @hashtag_pete suggests is a good idea but it does bring complications. One approach would be to do this unpivot in a separate table so that you have a Domains table like this:

AlexisOlson_0-1648068491720.png

and an Articles table like this:

AlexisOlson_1-1648068529588.png

And have them related like this:

AlexisOlson_2-1648068661185.png

View solution in original post

8 REPLIES 8
hashtag_pete
Helper V
Helper V

Hello @LisanSpiegelaar  , 

 

you need to go to Power Query and select the columns with the domains, in your example "Domain 1" and "Domain 2", then go to the Tab "Transform" and make "Unpivot Columns". 

You can then for example delete the empty ones or load it all to Power BI Desktop, in order to do further calculations there. 

 

If this helps, please give kudos and accept as solution. 

Best

hashtag_pete

Hi Pete,

Would that imply that I first have to duplicate the query? Because when I unpivot, those articles that have two domains show up as two different rows. For some other measures I have written DAX that for example averages the number of views:

Views(average) = 
AVERAGE(LinkedIn[Views])

 

Since, after unpivoting, one article can show up in two rows, I guess those measures do not give me the correct value anymore, right? I could solve this by duplicating the query and doing your trick in that query. Or could you think of a better way? Thanks!

Unpivoting as @hashtag_pete suggests is a good idea but it does bring complications. One approach would be to do this unpivot in a separate table so that you have a Domains table like this:

AlexisOlson_0-1648068491720.png

and an Articles table like this:

AlexisOlson_1-1648068529588.png

And have them related like this:

AlexisOlson_2-1648068661185.png

Thank you Alexis, this is the approach that works best!

HotChilli
Super User
Super User

What's the logic behind 'Living' getting 1 in the Number Of articles?

My mistake, there is no logic. I have been staring at these things for way too long 😂 Let me adjust my original post! Thanks for letting me know.

I thought this is the count of how many times was this category addressed?

In your example, Living exists once, Work twice and Care three times...

yes you are correct, I adjusted my mistake in my original post so you can disregard HotChilli's question 😊

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.