Forum Discussion
Create UNION keeping DAX calculated fields (ways to perform this)
- 7 years ago
hi, Anonymous
First, Each table argument of 'UNION' must have the same number of columns.
Second, for your requirement, you could add blank columns in SELECTCOLUMNS expression not in table.
For example:
SELECTCOLUMNS('Table',"a",[a],"b",[b],"blank c",BLANK())Best Regards,
Lin
HI, Anonymous
When you use UNION function to create the table,
Use SELECTCOLUMNS expression instead of a tanle name
for example:
Table = UNION(Table1,SELECTCOLUMNS(Table3,"A",[A],"B",[B],"C",[C]))
Best Regards,
Lin
Hello Li,
Many thanks for your suggestions. I tried to apply the solution you suggested. However, this solution still requires all the tables to have the same number of columns as I get the following message "Each table argument of 'UNION' must have the same number of columns.
Please see my example below:
As you can see some fields exist in both tables and some others don't. My task is to append the data of Table 2 just below of the data of Table 1 and the fields that do not exist in Table 1 or 2 to be blank automatically.
test teble = UNION(SELECTCOLUMNS('Table1'; "d"; [d]; "pi"; [pi]; "LA"; [LA]; "ba"; [ba]; "ve"; [ve]; "SO"; [SO]; "O"; [O]; "AV"; [AV]; "P"; [P]; "B"; [B]; "C"; [C]; "R"; [R]);
SELECTCOLUMNS('Table 2'; "d"; [d]; "LA"; [LA]; "pr"; [pr]; "ba"; [ba]; "BB"; [BB]; "F"; [FV]; "O"; [O]; "AV"; [AV]; "B"; [B]; "C"; [C]; "HA"; [HA]; "P"; [P]; "R"; [R]; "CO"; [CO]; "D"; [D]; "S"; [S]; "Con"; [Con)])
)
As I mentioned in the first message I would like to avoid the process of adding blank columns manually in all tables in order to meet the requirement to have all tables with the same amount of columns and also to have the trouble of sorting them correctly.
What do you think?
- v-lili6-msft7 years ago
Community Support
hi, Anonymous
First, Each table argument of 'UNION' must have the same number of columns.
Second, for your requirement, you could add blank columns in SELECTCOLUMNS expression not in table.
For example:
SELECTCOLUMNS('Table',"a",[a],"b",[b],"blank c",BLANK())Best Regards,
Lin- Anonymous7 years agoNot applicable
This is working fine! Many thanks for your help