Forum Discussion

sashakali's avatar
sashakali
Frequent Visitor
1 year ago
Solved

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 definitionTable1When I return name_comboWhen I return test_tableTable2

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

3 Replies

  • HotChilli's avatar
    HotChilli
    Icon for Community Champion rankCommunity Champion

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

    • lbendlin's avatar
      lbendlin
      Icon for Super User rankSuper User

      Exactly. Same with SWITCH.

       

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