cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
garythomannCoGC
Resolver III
Resolver III

how to add a literal row to a dax table

 

 

 

-- create two tables and join together
DEFINE
    TABLE AllTable     = DATATABLE ( "Column Name", STRING, {{"All"}} )
    TABLE SummaryTable = DATATABLE ( "Column Name", STRING, {{"Yes"}} )

    --TABLE UnionTable = UNION ( AllTable, SummaryTable )    -- 1
    TABLE UnionTable = UNION ( row ("Column Name", "All" ), SummaryTable )  -- 2
EVALUATE
    UnionTable
    --SummaryTable 
    --AllTable

 

 

 

Trying to sandwich a literal table with an existing table.  ie add a row to a single column table.

In dax studio getting the error  "Failed to resolve name 'SummaryTable'.  It is not a valid table, variable or function name".

 

Yet  SummaryTable  as the return value will give the "Yes" result without error.   --2 is another attempt and giving the same error result.

 

What am I missunderstanding with dax here?

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@garythomannCoGC , Try like

 

DEFINE
    var AllTable     = DATATABLE ( "Column Name", STRING, {{"All"}} )
    var SummaryTable = DATATABLE ( "Column Name", STRING, {{"Yes"}} )

    --var UnionTable = UNION ( AllTable, SummaryTable )    -- 1
     var UnionTable = UNION ( row ("Column Name", "All" ), SummaryTable )  -- 2
EVALUATE
    UnionTable
    --SummaryTable 
    --AllTable
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

View solution in original post

2 REPLIES 2
garythomannCoGC
Resolver III
Resolver III

@amitchandak Thank you for your reply.  Works for both UnionTable scenarios.  Doh, I had started with VAR's then got the error then switched to TABLE usage thinking the code needed tightening  ie dealing only with tables.

Just had a play and when the UnionTable  line is declared as TABLE we get the error.  

 

Oh boy that does not make sense!  Why does the declaration of UnionTable need to be VAR and bombs with TABLE!?

And which would you choose for the initial declarations?  VAR just seems too loose 🙂

 

Lol and which would you pick and why for the UNION statement?  I'm thinking  --1  as this looks more straightforward (maybe more SQL-ish :)) 

amitchandak
Super User
Super User

@garythomannCoGC , Try like

 

DEFINE
    var AllTable     = DATATABLE ( "Column Name", STRING, {{"All"}} )
    var SummaryTable = DATATABLE ( "Column Name", STRING, {{"Yes"}} )

    --var UnionTable = UNION ( AllTable, SummaryTable )    -- 1
     var UnionTable = UNION ( row ("Column Name", "All" ), SummaryTable )  -- 2
EVALUATE
    UnionTable
    --SummaryTable 
    --AllTable
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
!! Subscribe to my youtube Channel !!

Helpful resources

Announcements
May 23 2022 epsiode 5 without aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

Power BI Dev Camp Session 22 with aka link 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!