Forum Discussion

MSAYED26's avatar
MSAYED26
Helper II
3 years ago
Solved

distinct count

Hello , I want to count how many parts with supplier more than 2 and supplier equal 1 Part  Supplier W0030508752R A W0030508752R B W0030509095H-V1 A W0030509095H-V1 A W003050...
  • freginier's avatar
    3 years ago

    To count how many parts have a supplier more than 2 and a supplier equal to 1, you can use the following DAX formula:

    Count = COUNTROWS(FILTER(Table, Table[Supplier] = "1" || CALCULATE(COUNT(Table[Supplier]), ALLEXCEPT(Table, Table[Part])) > 2))

     

    Replace "Table" with the name of your table.

    This formula uses the FILTER function to create a filter context where the supplier is equal to "1" or where the count of suppliers for the same part is greater than 2. The COUNTROWS function then counts the number of rows that satisfy the filter context.

    Note that the ALLEXCEPT function removes all filters from the table except for the ones specified in the ALLEXCEPT arguments. In this case, we are keeping the filters on the "Part" column to ensure that we are counting suppliers for each unique part.

  • v-zhangti's avatar
    3 years ago

    Hi, MSAYED26 

     

    You can try the following methods.
    Measure:

    Count Supplier = CALCULATE(DISTINCTCOUNT('Table'[Supplier]),ALLEXCEPT('Table','Table'[Part]))
    More than 2 = CALCULATE(DISTINCTCOUNT('Table'[Part]),FILTER(ALL('Table'),[Count Supplier]>=2))
    Equal 1 = CALCULATE(DISTINCTCOUNT('Table'[Part]),FILTER(ALL('Table'),[Count Supplier]=1))

    Is this the result you expect?

     

    Best Regards,

    Community Support Team _Charlotte

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.