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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Medmbchr
Helper IV
Helper IV

SWITCH won't return a VAR table

Hi,

 

I am trying to build up a virtual table using UNION and SELECTCOLUMNS, this table is variable and its content is based on another column, hence am using SWITCH so that I can build up the appropriate table for each case.

 

However, my RETURN function doesn't recognize the table that I built in my VAR, I don't know why.

 

When I removed the SWITCH and applied directly UNION and SELECTCOLUMNS to see if my table would be recognized in my RETURN function, it worked fine.

 

So, does SWITCH function not return TABLE when used in a VAR?

 

The end is that I can calculate the standard deviation from a column in that virtual table I am building, hence here is how I would describe the structure of my code:

STANDARDDEVCOLUMN =

VAR TARGETTABLE = SWITCH([REVIEWTABLE],

1,UNION(SELECTCOLUMNS) <- 1st case

2,UNION(SELECTCOLUMNS) <- 1st case

3,UNION(SELECTCOLUMNS) <- 1st case

In Else I put a default table with 1 row only and predefined values)

 

RETURN

STDEVX.P (TARGETTABLE,[MYCOLUMN])

 

3 REPLIES 3
v-jialluo-msft
Community Support
Community Support

Hi  @Medmbchr ,

 

You can try using the IF function directly in RETURN. If this doesn't resolve the issue, you can provide sample data and projected output to further resolve it

 

Best Regards,
Gallen Luo

v-jialluo-msft
Community Support
Community Support

Hi  @Medmbchr ,

 

The switch function returns a single value of any type, not a table.

SWITCH - DAX Guide

vjialluomsft_0-1670565820427.png

 

Best Regards,
Gallen Luo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi @v-jialluo-msft 

 

Thanks for the reply, that was my suspicion and your confirmed it.

 

Hence, how can I return a table in a VAR function using conditions? I tried combinations of IF() but it didn't work out either.

 

Regards,

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.