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
rclay78
Frequent Visitor

Create new Column based on other column data

Please bare with me as I have only started using Power Bi and DAX a few months ago. With that said, I am trying to create a new column in my current table that is based on text string of another column. My table is tickets and the column I am looking at is labeled data. Basicaly like this: If 'Tickets'[data] contains abc then return abc to new column and if 'Tickets'[Data] contains "efg" then return efc in new column, etc, etc. I have about 5 different values I want to create in the new column.  A little confused how to proceed. Any help would be great.

 

 
1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @rclay78 ,

 

You may try this calculated column.

New Column = 
SWITCH (
    TRUE (),
    CONTAINSSTRING ( 'Tickets'[data], "abc" ), "abc",
    CONTAINSSTRING ( 'Tickets'[data], "efg" ), "efg",
    CONTAINSSTRING ( 'Tickets'[data], "hjk" ), "hjk",
    CONTAINSSTRING ( 'Tickets'[data], "awd" ), "awd",
    CONTAINSSTRING ( 'Tickets'[data], "dbb" ), "dbb"
)

6.png

 

Reference: SWITCH function
                 CONTAINSSTRING function


Best Regards,
Stephen Tao

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

4 REPLIES 4
v-stephen-msft
Community Support
Community Support

Hi @rclay78 ,

 

You may try this calculated column.

New Column = 
SWITCH (
    TRUE (),
    CONTAINSSTRING ( 'Tickets'[data], "abc" ), "abc",
    CONTAINSSTRING ( 'Tickets'[data], "efg" ), "efg",
    CONTAINSSTRING ( 'Tickets'[data], "hjk" ), "hjk",
    CONTAINSSTRING ( 'Tickets'[data], "awd" ), "awd",
    CONTAINSSTRING ( 'Tickets'[data], "dbb" ), "dbb"
)

6.png

 

Reference: SWITCH function
                 CONTAINSSTRING function


Best Regards,
Stephen Tao

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

mahoneypat
Employee
Employee

You can use a nested if then else to get your result in a custom column in the query editor

 

= if Text.Contains([Data], "abc") then "abc" else if Text.Contains([Data], "efg") then "efg" else ...

 

There are more sophisticated ways to do it but that should get you started.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


I already have my table established. I am wanting to create a new column in DAX

 

Ok.  You can do the same nested IF approach in DAX

 

NewColumn = IF(SEARCH("abc", Table[TextColumn]),,0)>0, "abc", IF("efg", ...

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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