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.
ERROR - "the expression contains columns from multiple tables, but only columns from a single table can be used in a True/False expression that is used as a table filter expression."
Here is the code sample for which I am getting the above error.
can anyone please help why am getting this error?
Top Purchaser Sales =
VAR _CurrentTopPurchaserCountry =
MAX(Customers[Country])
VAR _CurrentProductID =
MAX('Online Sales'[Product Key])
VAR _Sales =
CALCULATE(
[Sales Amount],
'Online Sales'[Product Key] = _CurrentProductID &&
Customers[Country] = _CurrentTopPurchaserCountry
)
RETURN
_Sales
Solved! Go to Solution.
Hey,
Here is the fix for your error
Before Change:
Top Purchaser Sales =
VAR _CurrentTopPurchaserCountry =
MAX(Customers[Country])
VAR _CurrentProductID =
MAX('Online Sales'[Product Key])
VAR _Sales =
CALCULATE(
[Sales Amount],
'Online Sales'[Product Key] = _CurrentProductID &&
Customers[Country] = _CurrentTopPurchaserCountry
)
RETURN
_Sales
After Change:
Top Purchaser Sales =
VAR _CurrentTopPurchaserCountry =
MAX(Customers[Country])
VAR _CurrentProductID =
MAX('Online Sales'[Product Key])
VAR _Sales =
CALCULATE(
[Sales Amount],
FILTER(
'Online Sales',
'Online Sales'[Product Key] = _CurrentProductID &&
RELATED(Customers[Country]) = _CurrentTopPurchaserCountry
)
)
RETURN
_Sales
So why did I get this error in the first place?
So what should we do when we need to filter based on columns from 2 different tables?
Hi @anonymous_98 ,
Can you try the following DAX:
Top Purchaser Sales =
VAR _CurrentTopPurchaserCountry =
MAX(Customers[Country])
VAR _CurrentProductID =
MAX('Online Sales'[Product Key])
VAR _Sales =
CALCULATE(
[Sales Amount],
'Online Sales'[Product Key] = _CurrentProductID &&
RELATED(Customers[Country]) = _CurrentTopPurchaserCountry
)
RETURN
_Sales
I am assuming there is an active relationship between both tables used in the your DAX expression.
Thanks,
Pragati
Hey @Pragati11 ,
Thanks for your help.
I was able to fix the issue.
Tried your code but it is not working the reason is the RELATED function needs to be used inside a FILTER function for it to work.
HI @anonymous_98
As far as I understand you want to know the top customer,
You need to choose "MAX" from 1 sales table
You choose the maximum country and the maximum unrelated product
If you want to know the top buyer you need to use the TOPN or RANX function
Hey,
Here is the fix for your error
Before Change:
Top Purchaser Sales =
VAR _CurrentTopPurchaserCountry =
MAX(Customers[Country])
VAR _CurrentProductID =
MAX('Online Sales'[Product Key])
VAR _Sales =
CALCULATE(
[Sales Amount],
'Online Sales'[Product Key] = _CurrentProductID &&
Customers[Country] = _CurrentTopPurchaserCountry
)
RETURN
_Sales
After Change:
Top Purchaser Sales =
VAR _CurrentTopPurchaserCountry =
MAX(Customers[Country])
VAR _CurrentProductID =
MAX('Online Sales'[Product Key])
VAR _Sales =
CALCULATE(
[Sales Amount],
FILTER(
'Online Sales',
'Online Sales'[Product Key] = _CurrentProductID &&
RELATED(Customers[Country]) = _CurrentTopPurchaserCountry
)
)
RETURN
_Sales
So why did I get this error in the first place?
So what should we do when we need to filter based on columns from 2 different tables?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
107 | |
88 | |
76 | |
67 |
User | Count |
---|---|
126 | |
111 | |
100 | |
83 | |
71 |