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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
msksenthil
Helper III
Helper III

Swapping tables in SWITCH DAX

I am trying to pass the tables based on another value. But it was showing an error when giving on it.

 

msksenthil_0-1633080158656.png

 

Any help, please?

5 REPLIES 5
PhilipTreacy
Super User
Super User

Hi @msksenthil 

OK, well, SWITCH can only return scalar values, not tables.  Perhaps you can rewrite your code so that the measure returns a value that indicates which table to use?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @msksenthil 

But the first parameter in your SWITCH isn't TRUE so how's it doing any comparison?  How are you intending to compare tables?  What is in these tables?

Can you share your file please.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


@PhilipTreacy Sorry, I can't share the file beacuse of the sensitivity. 

Variable _a3 might be any one of values {1,3,4}

And, I have 3 calculated tables _a4, _a6 and _a7

I want to return

_a4 table if _a3=1, 

_a6 table if _a3 = 3

else

_a7 table

 

Hope it clears my requirement

msksenthil
Helper III
Helper III

@PhilipTreacy 

 

I trying to swap the TABLES (multiple values like column) instead of value (single value) bases on the TRUE() condition

PhilipTreacy
Super User
Super User

Hi @msksenthil 

What exactly are you trying to do?  I don't understand how/why you are testing values and what to return.

It doesn't look like your SWITCH statements are correct.

The syntax is 

 

SWITCH
( 

VALUE_TO_TEST,

CONDITION_1, VALUE_TO_RETURN,

CONDITION_2, VALUE_TO_RETURN,

....

DEFAULT_VALUE_TO_RETURN
)

 

 

So you might typically use it like this

 

SWITCH
(
TRUE,

_var < 5 , "Less than 5",

_var < 10 , "Less than 10",

.....

"Greater than 100"
)

 

 

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.