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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Anonymous
Not applicable

Getting scalar error using Switch function

Very new to DAX. Trying to use Switch for the first time. I am getting the error 'The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.' I am not having any luck coming up with a solution. Here is the code:

IVC - Delivered Cubic Realization:=SWITCH(
     SEARCH("PL",FILTER('Invoice Fact', RELATED('Product Dimension'[Product Family Code]))),
              DIVIDE('Invoice Fact'[IVC - Delivered Amount Extended], 'Invoice Fact'[IVC - Cubic Conversion Footage]) * 1000
    ,SEARCH("VE",FILTER('Invoice Fact', RELATED('Product Dimension'[Product Family Code]))),
              DIVIDE('Invoice Fact'[IVC - Delivered Amount Extended], 'Invoice Fact'[IVC - Cubic Conversion Footage]) * 1000
    ,SEARCH("EWP",FILTER('Invoice Fact', RELATED('Product Dimension'[Product Family Code])),"BEAM",FILTER('Invoice Fact', RELATED('Product Dimension'[Product Category Code]))),
              DIVIDE('Invoice Fact'[IVC - Delivered Amount Extended], 'Invoice Fact'[IVC - Cubic Conversion Footage]) * 1000
    ,DIVIDE('Invoice Fact'[IVC - Delivered Amount Extended], 'Invoice Fact'[IVC - Cubic Conversion Footage])
)

2 REPLIES 2
Regex
Regular Visitor

Hi,

 

The code is very confusing and seems to have multiple issues.

 

However I can immediately see that you are getting that error because DIVIDE refers to columns directly without an aggregator over both the numerator and denominator (probably you'd want to use SUM). It won't be the only error even if you fix it.

 

I suggest first adding a helper column to Invoice Fact that contains a string (e.g. "EWP"), which will define what logic is used in the SWITCH table. You need to get that right first.

 

Good luck!

 

 

dedelman_clng
Community Champion
Community Champion

Hi @Anonymous  - Your use of SWITCH appears to be OK. It is the other functions that are an issue

 

SEARCH requires a scalar text value as its second parameter - FILTER returns a table.

 

SEARCH also generally needs a 4th parameter, which is what to do if SEARCH doesn't find what you're looking for (it returns ERROR if you omit the 4th parameter).  Your usage will be something like SEARCH("A", SearchInString, , 0)

 

Also, SEARCH returns an integer, not TRUE/FALSE, so you will need to compare the result of SEARCH to something

(SWITCH( SEARCH (...) > 0, ....)

 

This is a good resource for DAX functions: https://dax.guide/ 

 

Hope this helps

David

 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.