Forum Discussion

gregtm's avatar
gregtm
New Member
2 years ago
Solved

Count Rows in a column based on another column's distinct value

I want to total the Buyers in column B based on the PO in column A.  Example  1 PO = 3 buyers (Total column)  I have tried a couple of measures Distinctcount and Count but can't seem to get it.

POBuyerTotal
1001B3
1001C 
1001D 
1002A4
1002B 
1002C 
1002D 
1003B1
1004A1
1005A2
1005B 
1007A3
1007B 
1007C 
1008B1
1009B2
1009D 
1010A3
1010B 
1010C 
1011B2
1011D 
1012B1
1013A3
1013B 
1013C 
1020A3
1020B 
1020C 
1022A3
1022B 
1022C 
  • A measure like this should work:

    Buyer Count per PO = CALCULATE( DISTINCTCOUNT( [Buyer] ) , ALLSELECTED( {Buyer] ) )
     
    The reason for writing the measure this way is in your above example, you want the total number of buyers per PO within a table containing both PO and Buyer, so you need to remove the row context of Buyer from the calculation. This is what the ALLSELECTED here is doing.

2 Replies

  • CoreyP's avatar
    CoreyP
    Solution Sage

    A measure like this should work:

    Buyer Count per PO = CALCULATE( DISTINCTCOUNT( [Buyer] ) , ALLSELECTED( {Buyer] ) )
     
    The reason for writing the measure this way is in your above example, you want the total number of buyers per PO within a table containing both PO and Buyer, so you need to remove the row context of Buyer from the calculation. This is what the ALLSELECTED here is doing.
    • gregtm's avatar
      gregtm
      New Member

      Thank you very much.  That works perfectly.