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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jPinhao
Advocate II
Advocate II

DAX - Error on trying to return tables from an IF() statement

I'm trying to build a DAX expression that will join a table with 1 of 2 others, depending on whether one of these other tables is empty:

VAR OwnedIDs = IF(ISEMPTY(FilteredOwnedFeatures), 							
                     NATURALINNERJOIN(FeatureOwnedIDs, ALL(Dim_OwnedFeatures)),
                     NATURALINNERJOIN(FeatureOwnedIDs, FilteredOwnedFeatures))

This gives me an error: "The expressions refers to multiple columns. Multiple columns cannot be converted to a scalar value"

 

 

I can't figure out what is going on and how to get it to work. There doesn't seem to be any issues with the JOIN statements (they both work in isolation, however they break the if statement. FilteredOwnedFeatures is just a filtered version of Dim_OwnedFeatures so they should both have the same columns, and the resulting joins too.

 

Why is IF() getting confused with this piece of code? And can I rewritte this in a way that will work? In case this is a more obscure issue, here's the full DAX measure code:

Cumulative Potential Users = 
VAR SelectedFeatures = CALCULATETABLE(Fact_FeatureUsed, ALL(Dim_Date)) VAR
//Filter Dim_OwnedFeatures by only the selected features
FilteredOwnedFeatures = FILTER(Dim_OwnedFeatures,
CONTAINS(SelectedFeatures, [Feature], Dim_OwnedFeatures[Owned Feature])) VAR
// PROBLEM AREA
// Consider only ownership IDs for features we have selected, or OwnedIDs = IF(ISEMPTY(FilteredOwnedFeatures), NATURALINNERJOIN(FeatureOwnedIDs, ALL(Dim_OwnedFeatures)), NATURALINNERJOIN(FeatureOwnedIDs, FilteredOwnedFeatures))
RETURN CALCULATE([Cumulative Users], ALL(Fact_FeatureUsed[Feature]), OwnedIDs)

 

 

1 ACCEPTED SOLUTION
v-sihou-msft
Microsoft Employee
Microsoft Employee

@jPinhao

 

In DAX, you can't specify a dynamic filter context in CALCULATE(). And what IF statement returns should be value, if the value_if_ture is a column, it returns the value that corresponds to the current row. You can't make it returns a table context which contains multipe columns as the error message mentioned.

 

Regards,

View solution in original post

2 REPLIES 2
v-sihou-msft
Microsoft Employee
Microsoft Employee

@jPinhao

 

In DAX, you can't specify a dynamic filter context in CALCULATE(). And what IF statement returns should be value, if the value_if_ture is a column, it returns the value that corresponds to the current row. You can't make it returns a table context which contains multipe columns as the error message mentioned.

 

Regards,

Thanks for the insight Simon. I found a way around, changing one of my tables to ensure the query wouldn't end up empty and always get a meaningful result back - this has the side effect of having data in there which we don't care about, but it can be filtered out 🙂

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors