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
lastnn30
Post Patron
Post Patron

using substitute () to change 2 values.

Hi

I have a column called Gender which has values like M, and F. I want to use Subsitute() to replace M to Male and F to Female. So what I created a New Column and I wrote this dax

 

Gender_full = subsitute(Table1(Gender), "M", "Male"")

 

But that only change M to Male, how can I write one Dax function to subsitute both M and F at same time.

Thank you very much.SNAG-0086.jpg

3 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@lastnn30 You might kick yourself:

Gender Full Column = 
    SUBSTITUTE(
        SUBSTITUTE([Gender],"M","Male"),
        "F", "Female"
    )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

smpa01
Super User
Super User

@lastnn30  you can create a mapping table and utilize moving forward

 

Column =
VAR mapping =
    DATATABLE (
        "lookup", STRING,
        "val", STRING,
        {
            { "Male", "M" },
            { "M", "M" },
            { "F", "F" },
            { "Female", "F" }
        }
    )
RETURN
    MAXX (
        FILTER ( mapping, [lookup] = CALCULATE ( MAX ( 'Table'[Column1] ) ) ),
        [val]
    )

 

smpa01_0-1675720352799.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

FreemanZ
Super User
Super User

hi @lastnn30 

you may also try like:

Gender_full = IF([Gender]="M", "Male", "Female")

View solution in original post

3 REPLIES 3
FreemanZ
Super User
Super User

hi @lastnn30 

you may also try like:

Gender_full = IF([Gender]="M", "Male", "Female")
smpa01
Super User
Super User

@lastnn30  you can create a mapping table and utilize moving forward

 

Column =
VAR mapping =
    DATATABLE (
        "lookup", STRING,
        "val", STRING,
        {
            { "Male", "M" },
            { "M", "M" },
            { "F", "F" },
            { "Female", "F" }
        }
    )
RETURN
    MAXX (
        FILTER ( mapping, [lookup] = CALCULATE ( MAX ( 'Table'[Column1] ) ) ),
        [val]
    )

 

smpa01_0-1675720352799.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Greg_Deckler
Super User
Super User

@lastnn30 You might kick yourself:

Gender Full Column = 
    SUBSTITUTE(
        SUBSTITUTE([Gender],"M","Male"),
        "F", "Female"
    )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.