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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
df123445
Helper II
Helper II

Counting records only if they are also in another table

I have 2 tables:

"planned visits" and "visited"

 

PLANNED VISITS:

IDQuarterSALES REP
1Q1John
2Q1John
3Q1John
1Q2John
4Q1Rob
6Q1Rob

 

VISITED:

IDQuarter SALES REP
1Q1John
2Q1John
4Q1Rob

 

I have 2 measures that count how many clients each sales rep has per quarter:

CALCULATE(DISTINCTCOUNT('PLANNED VISITS'[ID]),GROUPBY('PLANNED VISITS', 'PLANNED VISITS'[Quarter], 'PLANNED VISITS'[SALES REP] ))
 
and 
CALCULATE(DISTINCTCOUNT('VISITED'[ID]),GROUPBY('VISITED', 'VISITED'[Quarter], 'VISITED'[SALES REP] ))
 
Unfortunately Sales reps do unplanned visits sometimes , so I may have the situations where the measure for "VISITED" is higher than the "PLANNED" measure. For example, the VISITED table may look like this:
 
IDQuarterSALES REP
1Q1John
2Q1John
4Q1Rob
99999Q1John
 
 
How can I make sure the second measure ONLY selects IDs that are in the PLANNED VISITS table? 
 
Hoping my explation is clear, TIA 
1 ACCEPTED SOLUTION
daircom
Resolver II
Resolver II

Hi @df123445 ,

 

Looking at the documentation of the CALCULATE function, you can see that you can add multiple filters (your GROUPBY is the first and only filter you apply). 

CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])

This means, you can simply add a comma and add another filter to only look at ID's available in your other table. Something like:

CALCULATE(
    DISTINCTCOUNT('VISITED'[ID]),
    GROUPBY('VISITED', 'VISITED'[Quarter], 'VISITED'[SALES REP] ),
    'VISITED'[ID] IN VALUES('PLANNED'[ID])
)

 

now you added anothter filter. 

View solution in original post

1 REPLY 1
daircom
Resolver II
Resolver II

Hi @df123445 ,

 

Looking at the documentation of the CALCULATE function, you can see that you can add multiple filters (your GROUPBY is the first and only filter you apply). 

CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])

This means, you can simply add a comma and add another filter to only look at ID's available in your other table. Something like:

CALCULATE(
    DISTINCTCOUNT('VISITED'[ID]),
    GROUPBY('VISITED', 'VISITED'[Quarter], 'VISITED'[SALES REP] ),
    'VISITED'[ID] IN VALUES('PLANNED'[ID])
)

 

now you added anothter filter. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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