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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
barrymac98
Regular Visitor

Is it possible to add multiple columns with DAX

Instead of adding columns one at a time using dax is it possible to add multiple columns in one go?  I can break the code up below to add one column at a time and it works, but when I try to combine it into one dax statement it doesn't. 

 

 

 

Alice =
 SWITCH(TRUE(),
 'Table'[Name] = "Alice", "Alice",
 'Table'[Name] = "Bob", UNICHAR(8203),
 'Table'[Name] = "Carol", REPT( UNICHAR(8203), 2),
 BLANK()
 )

Bob =
 SWITCH(TRUE(),
 'Table'[Name] = "Alice", UNICHAR(8203),
 'Table'[Name] = "Bob", "Bob",
 'Table'[Name] = "Carol", REPT( UNICHAR(8203), 2),
 BLANK()
 )

Carol =
 SWITCH(TRUE(),
 'Table'[Name] = "Alice", REPT( UNICHAR(8203), 2),
 'Table'[Name] = "Bob", UNICHAR(8203),
 'Table'[Name] = "Carol", "Carol",
 BLANK()
 )
1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @barrymac98 

If you want to add multiple columns at one time, you need to use calculated table, because it will return multiple columns, you cannot create them directly at the existed table. you can refer to the following sample.

Create a calculated table

 

Table2 =
ADDCOLUMNS (
    'Table',
    "Alice",
        SWITCH (
            TRUE (),
            'Table'[Name] = "Alice", "Alice",
            'Table'[Name] = "Bob", UNICHAR ( 8203 ),
            'Table'[Name] = "Carol", REPT ( UNICHAR ( 8203 ), 2 ),
            BLANK ()
        ),
    "Bob",
        SWITCH (
            TRUE (),
            'Table'[Name] = "Alice", UNICHAR ( 8203 ),
            'Table'[Name] = "Bob", "Bob",
            'Table'[Name] = "Carol", REPT ( UNICHAR ( 8203 ), 2 ),
            BLANK ()
        ),
    "Carol",
        SWITCH (
            TRUE (),
            'Table'[Name] = "Alice", REPT ( UNICHAR ( 8203 ), 2 ),
            'Table'[Name] = "Bob", UNICHAR ( 8203 ),
            'Table'[Name] = "Carol", "Carol",
            BLANK ()
        )
)

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-xinruzhu-msft
Community Support
Community Support

Hi @barrymac98 

If you want to add multiple columns at one time, you need to use calculated table, because it will return multiple columns, you cannot create them directly at the existed table. you can refer to the following sample.

Create a calculated table

 

Table2 =
ADDCOLUMNS (
    'Table',
    "Alice",
        SWITCH (
            TRUE (),
            'Table'[Name] = "Alice", "Alice",
            'Table'[Name] = "Bob", UNICHAR ( 8203 ),
            'Table'[Name] = "Carol", REPT ( UNICHAR ( 8203 ), 2 ),
            BLANK ()
        ),
    "Bob",
        SWITCH (
            TRUE (),
            'Table'[Name] = "Alice", UNICHAR ( 8203 ),
            'Table'[Name] = "Bob", "Bob",
            'Table'[Name] = "Carol", REPT ( UNICHAR ( 8203 ), 2 ),
            BLANK ()
        ),
    "Carol",
        SWITCH (
            TRUE (),
            'Table'[Name] = "Alice", REPT ( UNICHAR ( 8203 ), 2 ),
            'Table'[Name] = "Bob", UNICHAR ( 8203 ),
            'Table'[Name] = "Carol", "Carol",
            BLANK ()
        )
)

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Makes sense! thank you 🙂

Daniel29195
Super User
Super User

@barrymac98 

Not sure what you mean, 

but u can use addcolumns function in dax to add as many as you want 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

March 2024 PBI Gallery Image

Power BI Monthly Update - March 2024

Check out the March 2024 Power BI update to learn about new features.