Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Tevon713
Helper IV
Helper IV

Distinct Count of 2 tables if they matches + specific value

Hi All... I have 2 tables.

 

Created a measure is to find distinct count of "Acct" in table 1:  

Count Unique Acct = DISTINCTCOUNT(Table1[Acct]) or should it be count row?

 

I also need help in trying to find the following:

1. Find matches of "Acct" in Table 2 to "Acct" in Table 1 if so then return distinct count or count row.

2. Second part similar to previous #1 but to find distinct count for specific region ie "East" in Table 2 is 2 as 2 matches to table 1 and "West" should be 1 and so on.

 

Tevon713_0-1667341983206.png

 

Thank you all for your help.

 

1 ACCEPTED SOLUTION

Thanks @v-yangliu-msft.

 

I was thinking something more along the line of the following, which appeared to work.

 

Matches Measure = CALCULATE(DISTINCTCOUNT(Table2[Acct]) , FILTER(Table2,LOOKUPVALUE(Table1[Acct],Table1[Acct], Table2[Acct])))
 
Tevon713_0-1667396427712.png

And for specific region be like this.... 

 

Matches Measure 2 = CALCULATE(DISTINCTCOUNT(Table2[Acct]) , FILTER(Table2,LOOKUPVALUE(Table1[Acct],Table1[Acct], Table2[Acct])), Table2[Region]="East")

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Tevon713 ,

 

Here are the steps you can follow:

1. Create measure.

Measure =
var _select=SELECTCOLUMNS('Table2',"1",[Acct])
var _table1=
SUMMARIZE('Table1','Table1'[Acct],'Table1'[Region],
"Flag",IF('Table1'[Acct] in _select,1,0))
return
IF(
    MAX('Table2'[Region]) in SELECTCOLUMNS(_table1,"Region",[Region]) ,
    COUNTX(FILTER(_table1,[Flag]=1),[Region]))

2. Result:

vyangliumsft_0-1667353608475.png

 

Best Regards,

Liu Yang

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

Thanks @v-yangliu-msft.

 

I was thinking something more along the line of the following, which appeared to work.

 

Matches Measure = CALCULATE(DISTINCTCOUNT(Table2[Acct]) , FILTER(Table2,LOOKUPVALUE(Table1[Acct],Table1[Acct], Table2[Acct])))
 
Tevon713_0-1667396427712.png

And for specific region be like this.... 

 

Matches Measure 2 = CALCULATE(DISTINCTCOUNT(Table2[Acct]) , FILTER(Table2,LOOKUPVALUE(Table1[Acct],Table1[Acct], Table2[Acct])), Table2[Region]="East")

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.