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

Replace values within a a group of text in a column


I have a column that has a group of text and I want replace some key words within that group of text. For Example, I want take the value (Right;Sessions) and change to (Right,Session). I am not sure how to do that.

 

This is what I am hoping to achieve: 

Keyphrases                                        New Column
Right;Sessions                                     Right;Session
No Sessions                                        NO Session
Unplanned, Sessions                          Unplanned, Session

 

 

I try to use this switch statement to achieve my goal, but it did not work.

 

KeyPhrasesClean =
VAR SelectedName = SELECTEDVALUE([Keyphrases]) //This returns the selected value from original name in the table visual.
RETURN
SWITCH( SelectedName, //This evaluates true if the 2nd argument is ==, else it evaluates false and continues through the switch
"meetings", "meeting",
"sessions", "session",
"rooms", "room",
"SelectedName" //This simply returns the selected name if the name doesn't equal the values listed above
)

 

Regards,

Richard

2 ACCEPTED SOLUTIONS
AlexisOlson
Super User
Super User

If you just have a few replacements, then you can use nested SUBSTITUTE functions.

 

KeyPhrasesClean =
VAR SelectedName = CALCULATE ( SELECTEDVALUE ( [Keyphrases] ) )
RETURN
    SUBSTITUTE (
        SUBSTITUTE (
            SUBSTITUTE (
                SelectedName,
                "Meetings", "Meeting"
            ),
            "Sessions", "Session"
        ),
        "Rooms", "Room"
    )

View solution in original post

I've tweaked it slightly so that it should work either as a measure or a calculated column.

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

If you just have a few replacements, then you can use nested SUBSTITUTE functions.

 

KeyPhrasesClean =
VAR SelectedName = CALCULATE ( SELECTEDVALUE ( [Keyphrases] ) )
RETURN
    SUBSTITUTE (
        SUBSTITUTE (
            SUBSTITUTE (
                SelectedName,
                "Meetings", "Meeting"
            ),
            "Sessions", "Session"
        ),
        "Rooms", "Room"
    )

@AlexisOlson 

Alexis, thanks for the quick reply.  I am not sure if I am doing something wrong but it the solution you provided returns a blank row.  Please note that I am trying to return the substituted value in a new column.

I've tweaked it slightly so that it should work either as a measure or a calculated column.

@AlexisOlson ,

Thank you Alexis.  It works to perfection now.   I appreciate the quick, and outstanding response.

 

Best,

rpricien

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.