Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Data Modeling - Unpivot? Best Practice Needed

Dear Power BI Community,

 

Here is how my data is originally structured:

 

Customer IDTotal ID'sProducts
18Product A, Product B, Product C
25Product B, Product C
36Product A
49Product B, Product C
54Product C

 

I add 3 columns that look up the products:

 

Customer IDTotal ID'sProductsProduct AProduct BProduct C
18Product A, Product B, Product C111
25Product B, Product C011
36Product A100
49Product B, Product C011
54Product C001

 

Then I pivot the Data Set:

 

Company IDTotal ID'sAttributeValue
18Product A1
18Product B1
18Product C1
25Product A0
25Product B1
25Product C1
36Product A1
36Product B0
36Product C0
49Product A0
49Product B1
49Product C1
54Product A0
54Product B0
54Product C1

 

But now when I go to calculate "Total ID's" that number is obviously being triple counted.

 

I'm sure there is a better way to go about it but I am just not thinking about it in the right way.

  • Hi Anonymous ,

     

    If you want to have the information at the Product level in my opinion you did the correct steps, however you need to take into account that the fields neeed to be handle in diferent ways when summarizing.

     

    In your specific case the ID column needs to be summarized on DISTINCT COUNT and not on COUNT, because you will have triple calculation as you are getting.

     

    Regards,

    MFelix

5 Replies

  • Hi Anonymous ,

     

    If you want to have the information at the Product level in my opinion you did the correct steps, however you need to take into account that the fields neeed to be handle in diferent ways when summarizing.

     

    In your specific case the ID column needs to be summarized on DISTINCT COUNT and not on COUNT, because you will have triple calculation as you are getting.

     

    Regards,

    MFelix

    • Anonymous's avatar
      Anonymous
      Not applicable

      That's good to know! So to sum up all the Total ID's, I was thinking a Dax Forumla something like:

       

      Total ID's = calculate(sum(total ID's),Distinct(Company ID))

       

      But that is still giving me the triple counting.

       

      MFelix 

      • MFelix's avatar
        MFelix
        Super User

        Hi Anonymous ,

         

        You just need to use the DISTINCTCOUNT:

         

        Total ID's = DISTINTCTCOUNT(Table[ID])

         

        Then depending on the context of the visual you are using you will get the filter by company, product, whatever other field you add to context.

         

        Regards,

        MFelix