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
kfortenberry
Frequent Visitor

INTERSECT between 2 Tables with different Filter Values

Hi Everyone, I would appreciate any assistance you could provide.  I have two tables that share a Many to Many relationship. The first is a record of all activities created by our staff and the second is a list of all policies sold. (The actual tables are considerably larger and contain many more columns.)

 

Activities: need to filter for only TF activities

Client CodeActivity Type Client Name 
A123TF Adam 
B229TF Bob 
C234CT Charles 
E762NO David 
A123TF Adam 
B229NO Bob 
C234CT Charles 
A123CT Adam 
E762TF David 

 

Policies Sold: need distinct policy numbers

Client CodePolicy Number Premium 
A12311111 $          100.00
B22922222 $          300.00
C23433333 $          200.00
E76244444 $          900.00
A12311111 $            50.00
A12355555 $          400.00

 

I need to build a formula that shows a count of all policies sold only for those client codes where a TF activity was entered.  If more than one unique Policy Number exists on a client code I need to count each of these, but I would not want to count duplicates of the same policy number on the same client code. 

6 REPLIES 6
DataNinja777
Super User
Super User

Hi @kfortenberry ,

 

Regarding the many-to-many relationship, it appears that you need to create a separate dimension table for Client Code, and create a deta model like below, where many-to-one relatinoships are created for the two fact tables. 

DataNinja777_0-1728384119276.png

Then, you can write a measure like below:

Activity TF =
CONCATENATEX (
    DISTINCT ( Activities[Activity Type] ),
    IF ( Activities[Activity Type] = "TF", Activities[Activity Type], BLANK () )
)

Which is then brought to the Client Code dimension table,

DataNinja777_1-1728384398046.png

This is brought through the normal relationship path to the other fact table, Policies Sold.

DataNinja777_2-1728384467668.png

You can then write a measure like the one below to identify the distinctcount of policy numbers where the client codes have an 'TF' activity type.

Policy Number distinctcount (TF) =
CALCULATE (
    DISTINCTCOUNT ( 'Policies Sold'[Policy Number] ),
    KEEPFILTERS ( 'Policies Sold'[TF] = "TF" )
)

The resulting output is displayed below.

DataNinja777_3-1728384656494.png

Please let me know if the result is line with your expectations. 

I have attached an example pbix file for your reference.

 

Anonymous
Not applicable

Hi @kfortenberry ,

 

Have a good day. Have you resolved the issue?

 

Best Regards,

Wearsky

SachinNandanwar
Super User
Super User

As there exist a many to many relationship across the two tables, create a calcuated column in the Policy table.

Count Of Policies= COUNTX (
    SELECTCOLUMNS (
        FILTER ( RELATEDTABLE ( 'Activities' ), 'Activities'[Activity Type] = "TF" ),
        "Cnt", 'Policy'[Policy Number]
    ),
    'Policy'[Policy Number]
)

  



Regards,
Sachin
Check out my Blog

Thank you for your assistance. I am receiving the following error when I try to implement this formula:

 

"A single value for column 'PolicyNumber' in table 'Policy' cannot be determined. Thias can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

You have to create a calculated column.



Regards,
Sachin
Check out my Blog
Selva-Salimi
Super User
Super User

Hi @kfortenberry 

 

you can write a measure as follows:

 

measure count_policy := var tbl1= summarize( filter (activities, [activity type] = "TF") , activities [client code])

var tbl2 = summarize ( filter (policies sold , policies sold [client code] in tbl1) , policies sold [ client code] , policies sold [ policy number]  )

 

return countrows (tbl2)

 

 
If this post helps, then I would appreciate a thumbs up  and mark it as the solution to help the other members find it more quickly. 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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