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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sashakali
Frequent Visitor

SELECTCOLUMNS throwing "not a valid table expression" when inside IF statement

Hello all,

I am trying to create a table but I'm running into an issue where the SELECTCOLUMNS does not return a "valid table expression" when it comes from an IF statement. If it is outside the IF statement, it works fine. I've already checked the conditional and it works fine. There are no relationships in the model. 

I've attached images of my DAX formula. In this example, my test_table variable works fine when I return it, but if I try to return name_combo (where the only possible outcome is test_table), I get thrown the error message. Same thing happens if I try to append Table2_Name to test_table and name_combo using ADDCOLUMNS (test_table works whereas name_combo does not).

Any help would be appreciated, thank you. test_table definitiontest_table definitionTable1Table1When I return name_comboWhen I return name_comboWhen I return test_tableWhen I return test_tableTable2Table2

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

This looks a bit overcomplex but the error is returned because IF can only return a scalar value (so not a table)

View solution in original post

3 REPLIES 3
sashakali
Frequent Visitor

Thank you both @HotChilli @lbendlin for the help and helping me understand Power BI a little better

HotChilli
Super User
Super User

This looks a bit overcomplex but the error is returned because IF can only return a scalar value (so not a table)

Exactly. Same with SWITCH.

 

You need to calculate both tables speculatively, and then do the IF thing later.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.