Forum Discussion
How to use (COUNTIF) function in Power BI Desktop between 2 tables
- Anonymous2 years ago
Hi MhdMur ,
Based on your description, and based on my understanding, if there are duplicate values in Table II, I'm not quite sure if you need to count all Table I values that appear in Table II, or just how many unique Table I values appear in Table II i.e. de-duplicated. You can try the following two methods.
Here are my test data:1. Calculate contains duplicate values
Count of Customer ID in Table 1 = COUNTROWS( FILTER( 'Table1', NOT(ISBLANK('Table1'[Table1 customer ID])) && CALCULATE( COUNTROWS('Table2'), FILTER( 'Table2', 'Table2'[Table2 customer ID] = 'Table2'[Table2 customer ID] ) ) > 0 ) )2. Calculate without duplicates
Count = COUNTROWS( FILTER( 'Table1', NOT(ISBLANK( LOOKUPVALUE( 'Table2'[Table2 customer ID], 'Table2'[Table2 customer ID], 'Table1'[Table1 customer ID] ) ) ) ) )Best regards
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi MhdMur ,
Based on your description, and based on my understanding, if there are duplicate values in Table II, I'm not quite sure if you need to count all Table I values that appear in Table II, or just how many unique Table I values appear in Table II i.e. de-duplicated. You can try the following two methods.
Here are my test data:
1. Calculate contains duplicate values
Count of Customer ID in Table 1 =
COUNTROWS(
FILTER(
'Table1',
NOT(ISBLANK('Table1'[Table1 customer ID]))
&&
CALCULATE(
COUNTROWS('Table2'),
FILTER(
'Table2',
'Table2'[Table2 customer ID] = 'Table2'[Table2 customer ID]
)
) > 0
)
)
2. Calculate without duplicates
Count = COUNTROWS(
FILTER(
'Table1',
NOT(ISBLANK(
LOOKUPVALUE(
'Table2'[Table2 customer ID],
'Table2'[Table2 customer ID],
'Table1'[Table1 customer ID]
)
)
)
)
)
Best regards
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly