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
wem
Frequent Visitor

RETURN of SWITCH statements (via variables) via New Column

Hello,

I'm trying to find the right way to RETURN the values defined in the switch statements (Variables). Initially I tried to do this via a new SWITCH statement but that didn't work. I also experimented with IF but wasn't succesfull either.
Each of the VAR-statements returns the expected value when used seperately in a column. But I can't have the results of the different SWITCH statements returned in one column.
Any advice on this?
Thanks in advance
Wim 

Fruit =
VAR PEER =
SWITCH (
TRUE (),
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "golden" ), "PEER",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "jonagold" ), "PEER",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "granny smith" ), "PEER",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "peche" ), "PEER",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "nectarine" ), "PEER",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "meloen" ), "PEER",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "ananas" ), "PEER",
"-"
)

VAR APPEL =
SWITCH (
TRUE (),
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "opel" ), "APPEL",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "bmw" ), "APPEL",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "mini" ), "APPEL",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "rolls" ), "APPEL",
"-"
)

VAR KIWI =
SWITCH (
TRUE (),
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "stoel" ), "KIWI",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "tafel" ), "KIWI",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "raam" ), "KIWI",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "deur" ), "KIWI",
CONTAINSSTRING ( WORKGROUPSTATS[DNIS], "vuur" ), "KIWI",
"-"
)
RETURN



1 ACCEPTED SOLUTION
KeyurPatel14
Resolver IV
Resolver IV

Hi @wem ,
You can return only one variable using RETURN in dax.
If you want to return all the variables then you can concate those 3 variables and then you can return it.
If you have any queries then please let me know and if this is not working for you then please share your expected result so that I can help you.
Thank you.

View solution in original post

2 REPLIES 2
KeyurPatel14
Resolver IV
Resolver IV

Hi @wem ,
You can return only one variable using RETURN in dax.
If you want to return all the variables then you can concate those 3 variables and then you can return it.
If you have any queries then please let me know and if this is not working for you then please share your expected result so that I can help you.
Thank you.

Hi @KeyurPatel14 ,

The concatenation was exactly what I was looking for. I didn't expect to become the desired result this way.

Thank you very much for your suggestion/solution.

regards

Wim 

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.

Top Solution Authors