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
webportal
Impactful Individual
Impactful Individual

CALCULATE with OR condition in two tables

Hello,

 

In order to Sum the sales amount of blue products OR products that belong to category shoes, I'm using the following DAX expression:

 

CALCULATE(

SUM(Table[SalesAmount]),

FILTER(

Table,

Table[Color] = "Blue" ||

Table[Category] = "Shoes")

)

However, this doesn't work with two different tables (Colors and Categories), like:

 

CALCULATE(

SUM(Table[SalesAmount]),

FILTER(

Table,

Colors[Color] = "Blue" ||

Categories[Category] = "Shoes")

)

Can anyone help?

 

Thanks!

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

Hi @webportal

 

I got this working in a calculated measure.  You may just need to add the RELATED function to the OR condition

 

CALCULATE(
	SUM('Table'[SalesAmount]),
	FILTER(
		'Table',
		RELATED(Colors[Color]) = "Blue" || 
		RELATED(Categories[Category]) = "Shoes")
	)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
Phil_Seamark
Employee
Employee

Hi @webportal

 

I got this working in a calculated measure.  You may just need to add the RELATED function to the OR condition

 

CALCULATE(
	SUM('Table'[SalesAmount]),
	FILTER(
		'Table',
		RELATED(Colors[Color]) = "Blue" || 
		RELATED(Categories[Category]) = "Shoes")
	)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Sure, it works pretty well, thank you!
I suppose the "theory" behind this solution is to "bring" the Colors and Categories tables to the Table, treating them as one.
Really cool!

Yeah, having relationships is effectly giving you a logical table that includes all the columns from the table on the 1 side of the relationship on the table from the many side.

 

Good to hear it works!


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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.