Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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!

  • 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:

    and an Articles table like this:

    And have them related like this:

8 Replies

  • HotChilli's avatar
    HotChilli
    Icon for Community Champion rankCommunity Champion

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      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.

      • hashtag_pete's avatar
        hashtag_pete
        Icon for Helper V rankHelper V

        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...

  • Hello Anonymous  , 

     

    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

    • Anonymous's avatar
      Anonymous
      Not applicable

      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!

      • AlexisOlson's avatar
        AlexisOlson
        Icon for Super User rankSuper User

        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:

        and an Articles table like this:

        And have them related like this: