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

DAX Measure Intersect with Slicers

How do I do the equivalent of the following T-SQL code in a DAX measure:

 Also, I don't want to hard code values. I want Product and InsuranceCompany fields to be slicers.

 

select distinct(Table1.Client)

from Table1

where Table1.Product ='AUTO' AND Table1.InsuranceCompany = 'AMCO'

 

INTERSECT

 

select distinct(Table1.Client)

from Table1

where Table1.Product ='FIRE' AND Table1.InsuranceCompany   = 'Allied P & C Ins. Company'

 

Thanks in advance.

1 ACCEPTED SOLUTION

Yeah, that's an issue. You could create a New Table and just return the unconcatenated result but this would not be dynamic. See my idea about this here:

 

https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/33890335-table-visualization-tied...

 

Vote for it!!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

This should be doable. Can you post some sample data in a format that can be copy and pasted easily please? It's a lot of work to manually create the data.

 

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I apologize for lack of data. Here is a sample table:

 

ProductInsuranceCompanyClient
AUTOAMCODavid Brown
FIREAllied P & C Ins. CompanyDavid Brown
AUTOAMCOJames Smith
FIREAllied P & C Ins. CompanyJames Smith
AUTOAMCOJeff Wilson
FIREAllied P & C Ins. CompanyJeff Wilson
AUTOAMCOLinda Mcdonald
FIREAllied P & C Ins. CompanyLinda Mcdonald
AUTOAMCOSarah Engler
FIREAllied P & C Ins. CompanySarah Engler
HOMEChubbJohn Johnson
BOATTransamericaBill Jones
PETSAllied GroupJack Johnson

Thank you for the quick reply. I'll let you know if this works for my model.

Technically, you do not need the relationships for the measure to work but you will need two sources for Product and Insurance Company for your slicers because you need them to be indepenent of one another.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks much Greg that helped a lot. Once last thing, the resultset is coming back in one cell of a table,

 

(Joe Johnson, Jack Jones, Joe Smith) all together. Is there a way to split the results into individual rows?

 

Thanks again for your help!

Yeah, that's an issue. You could create a New Table and just return the unconcatenated result but this would not be dynamic. See my idea about this here:

 

https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/33890335-table-visualization-tied...

 

Vote for it!!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

OK, if you have this:

 

image.png

 

Then you can do this:

 

Clients = 
VAR tmpTable1 = FILTER(ALL('#Products'),'#Products'[Product]=MAX('#ProductsProduct'[Product])&&'#Products'[InsuranceCompany]=MAX('#ProductsInsurance'[InsuranceCompany]))
VAR tmpTable2 = FILTER(ALL('#Products'),'#Products'[Product]=MAX('#ProductsProduct (2)'[Product])&&'#Products'[InsuranceCompany]=MAX('#ProductsInsurance (2)'[InsuranceCompany]))
VAR tmpTable1a = DISTINCT(SELECTCOLUMNS(tmpTable1,"Client",[Client]))
VAR tmpTable2a = DISTINCT(SELECTCOLUMNS(tmpTable2,"Client",[Client]))
VAR retTable = INTERSECT(tmpTable1a,tmpTable2a)
RETURN CONCATENATEX(DISTINCT(retTable),[Client],",")

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

How do I do the equivalent of the following SQL code in a DAX measure:

 

select distinct(Table1.Client)

from Table1

where Table1.Product ='AUTO' AND Table1.InsuranceCompany = 'AMCO'

 

INTERSECT

 

select distinct(Table1.Client)

from Table1

where Table1.Product ='FIRE' AND Table1.InsuranceCompany   = 'Allied P & C Ins. Company'

 

Another piece is that I don't want to hard code values. I want Product and InsuranceCompany fields to be slicers.

 

Thanks in advance.

 

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.