Forum Discussion
Default values for field parameter with language support?
The error you're encountering, "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value," indicates that one or more expressions in your DAX code are returning multiple values where a single value is expected. This typically happens when you're trying to return a table or multiple values in a context where a single value is required, such as a measure or a variable.
In your case, the issue seems to be related to the fact that you're trying to return multiple rows of values within the SWITCH function, which expects a single scalar value for each case.
To resolve this issue, you need to restructure your DAX code so that it returns a single value for each case in the SWITCH function. One approach could be to return a single concatenated string that represents all the fields for a given language. Here's how you can adjust your code:
_p_location_resolution =
VAR SelectedLanguage = SELECTEDVALUE('languages'[ISO abbreviation], "en")
RETURN
SWITCH(
SelectedLanguage,
"en", CONCATENATEX({"region", "country", "city", "terminal"}, [Value], ", "),
"sv", CONCATENATEX({"region", "land", "stad", "terminal"}, [Value], ", "),
"se", CONCATENATEX({"región", "país", "ciudad", "terminal"}, [Value], ", "),
// default to english
CONCATENATEX({"region", "country", "city", "terminal"}, [Value], ", ")
)
In this code:
- CONCATENATEX is used to concatenate the values of each field into a single string.
- The {} syntax is used to create an array of field names for each language.
- [Value] represents the value associated with each field.
This way, your DAX expression returns a single string for each language, which can be used as the default definition for your field parameter. Make sure to adjust [Value] with the appropriate expression that retrieves the values you want to concatenate for each field.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.