Forum Discussion

ihungko's avatar
ihungko
Frequent Visitor
2 years ago

How to count based on another column

Hi community folks,

 

I am building a KPI dashboard, but kind of struggling to write the correct measure. Can you please kindly help? Thanks a lot!

 

My dataset is like this, I want to calculate certain opportunity # based on the KPI criteria. The criteria is as follow:

  • Calculate Won / Pending Opportunity #, for each opportunity, 1 credit for each unique KPI Product Group 
  • For example,
    • Opportunity X, there are 2 products in two different KPI Product Group, so it will get 2 credits for Pending;
    • Opportunity Y, there are 3 products, but only in 2 unique KPI Product Group, so it will also get 2 credits for Pending;
    • Opportunity Z, there are 4 products all in KPI Product Group B, so it will only get 1 credit for Won

 

Opportunity NameProduct NameStageKPI Product Group
Opportunity XProduct A1PendingA
Opportunity XProduct B1PendingB
Opportunity YProduct A1PendingA
Opportunity YProduct A2PendingA
Opportunity YProduct B1PendingB
Opportunity ZProduct B1WonB
Opportunity ZProduct B2WonB
Opportunity ZProduct B3WonB
Opportunity ZProduct B4WonB

3 Replies

  • Uzi2019's avatar
    Uzi2019
    Community Champion

    Hi ihungko 
    You can simply write DISTINCTCOUNT().
    If you want to take count against only opportunity name.

     

    If this not what you are looking for then let me know the expected output like what other columns you are expecting and count value against it.

     

     

     

    • ihungko's avatar
      ihungko
      Frequent Visitor

      Hi Uzi, thanks for your reply.

       

      DISTINCTCOUNT was my first option, however, there is a sistuation when kpi product group has more than 2, for example like the table below:

       

      The desired outcome would be 

      Opportunity NameCredit
      Opportunity X1
      Opportunity Y1
      Opportunity Z1
      Opportunity AA2
      TOTAL5

       

      But if I use DISTINCTCOUNT on KPI Product Group, it will be 3 in total,

       

       

       

       

      Opportunity NameProduct NameStageKPI Product Group
      Opportunity XProduct APendingA
      Opportunity YProduct APendingA
      Opportunity ZProduct APendingA
      Opportunity AAProduct BPendingB
      Opportunity AAProduct CPendingC
      • ihungko's avatar
        ihungko
        Frequent Visitor

        Uzi2019 

         

        I created a column concatenating Opportunity Name and KPI Product Group, and then use Distinctcount. It worked! 

         

        But I am still wondering if there's more efficient / lighter way to do so.