Return a Table With an IF Statement

Hi

This is a re-post from the Power BI community: Return a Table With an IF statement

The solution given solved my business need, but not my DAX challenge.

The below code should return a table (“_TableAdi” or “_TableTamir”) but instead, I get an error.

dynamicSlicer =
VAR _TableAdi = SUMMARIZECOLUMNS(COSTORCOUNT[Flag])
VAR _TableTamir = SUMMARIZECOLUMNS(COSTORCOUNT[Flag],FILTER(COSTORCOUNT,COSTORCOUNT[Flag]=0))

VAR _Table = IF( SELECTEDVALUE(parameterTable[parameter]) = 1,
                         _TableAdi, _TableTamir)

return _Table 

I’m getting the following error: “The expression specified in the query is not a valid table expression.”

Can anyone suggest a solution?

Thank you,
Tamir

@Tamiri You can’t return a table using IF/SWITCH. This is not allowed.

1 Like

Hello @Tamiri

Did the responses above help solve your query?

If not, can you let us know where you’re stuck and what additional assistance you need?

If it did, please mark the answer as the SOLUTION by clicking the three dots beside Reply and then tick the check box beside SOLUTION

Thank you

Hi @Tamiri

We’ve noticed that no response was received from you on the post above.

Just following up if you still require assistance to solve your inquiry.

In case there won’t be any activity on it in the next few days, we’ll be tagging this post as Solved.

Hi @Tamiri

Due to inactivity, we’d like to conclude that you no longer require assistance to solve your inquiry.

If you have a follow question or concern related to this topic, please remove the Solution tag first by clicking the three dots beside Reply and then untick the check box

Hi,
Why is this not allowed?
How else can this be achieved?

Thank you,
Tamir

Hello @Tamiri , and thank you for posting your question to the Forum.

Quite recently, the same question Return a Table With a SWITCH was added to Microsoft Power BI Community, and answered by Greg Deckler who offered an alternative solution.

Adding my $0.02 (though @AntrikshSharma and Greg Deckler are correct):

Both IF and SWITCH are Logical Functions. You would then need to pass the result to a Table Manipulation function to return a table or manipulate existing tables. Examples of this can be found on the Microsoft Power BI Community Forum with this pattern.