Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Create a custom measure based on matrix

I have the following matrix:

 

 

What I want is to get the following calculation as a number (%):

Calc = (Count of Promoter - Count of Detractor)/Total (%)

 

How do I do this, to display it as a card?

  • Anonymous try this:

     

    Total Count = COUNTROWS ( YourTable  )
    
    Calc = 
    DIVIDE (
       CALCULATE ( [Total Count], YourTable[NPS_Segment] = "Promoter" ) -
       CALCULATE ( [Total Count], YourTable[NPS_Segment] = "Detractor" ),
       [Total Count]
    )

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

12 Replies

  • Anonymous try this:

     

    Total Count = COUNTROWS ( YourTable  )
    
    Calc = 
    DIVIDE (
       CALCULATE ( [Total Count], YourTable[NPS_Segment] = "Promoter" ) -
       CALCULATE ( [Total Count], YourTable[NPS_Segment] = "Detractor" ),
       [Total Count]
    )

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for the repy parry2k . However, the calculation doesn't seem correct. It doesn't give me the expected result (expected output = 46.07%, actual output = 2.98%).

      I checked, and for example each calculation within the divide does not give me the correct value. For example, 

      CALCULATE ( 'NPS_Redeemers'[Total Count], 'NPS_Redeemers'[NPS_SEGMENT] = "Promoter" ) evaluate to 397 when it should actually just be equal to the Count of Promoter from the matrix, i.e. 5402.
  • Anonymous Can you post sample raw data in the table format? It has something to do with the data structure.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Here is some sample data - note that MSISDN contains unique customer IDs

       

      MSISDN  NPS_SEGMENT

      123          Detractor

      234          Passive

      345          Promoter

      456          Promoter

      567          Detractor

  • Anonymous the formula I gave you, how you try to visualize it? In a card visual?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Yes, in a card

  • Anonymous then it should work, what is TOTAL COUNT? Is it a measure? What is the expression for this measure?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Yes, I created Total Count as a measure as specified in your first reply 

      Total Count = COUNTROWS ( Table  )

       which if I visualise it in a card, it gives the correct number (7957). The problem seems to be in the calculations within the DIVIDE

  • Anonymous when you added this measure and visualize in the card, you are not getting correct result? Can you confirm?

     

    CALCULATE ( [Total Count], 'NPS_Redeemers'[NPS_SEGMENT] = "Promoter" ) 
    • Anonymous's avatar
      Anonymous
      Not applicable

      Exactly, adding that as a measure should theoretically give me row 1 of the matrix in the question (i.e. 5402) but it gives me 397

  • Anonymous weird, are you ok to share the pbix file, remove any sensitive information before sharing, just keep the basic data.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Ok this is completely my mistake - I had two tables named very similarly and I was mixing up the values from each one.

       

      Your solution works just fine now that this has been sorted!! Thank you for your patience