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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Larry_Wang
Helper I
Helper I

How to change values with DAX

Hi Everyone,

 

I have a table below and I want to create a new column called category with only two items, fruit & other. How to do this with DAX?

 

IDNameCATEGORY
1APPLEfruit
2PEACHfruit
3ORANGEfruit
4ORANGEfruit
5PEACHfruit
6PEACHfruit
7PEACHfruit
8APPLEfruit
9TABLEother
10PENother
11GRAPEfruit
12GRAPEfruit
13TABLEother
14PENother
15PENother
16APPLEfruit
17ORANGEfruit
18PENother
19GRAPEfruit

 

Thanks,

 

Larry

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

Here is an example:

Category = IF(Category[Name] in {"TABLE","PEN"},"OTHER","FRUIT")
ValtteriN_0-1639638200477.png


I hope this helps to solve your issue and if it does consider accepting this as a solution and giving the post a thumbs up!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Larry_Wang
Helper I
Helper I

Hi @ValtteriN 

 

May be one more question. I have a similar table below and I also want to create a new column called region. Is there an easy way to do this using DAX?

I tried to duplicate a column in Query editor and use replace values command. But it doesn't support for using of wild cards like " * ". If I have many values then I need to do it one by one. For example how to change all location name with a suffix " Asia " to " APAC " in new column?

 

LocationRegion (New Column)
America/MexicoAMERICA
America/New yorkAMERICA
Asia/CalcuttaAPAC
Asia/ShanghaiAPAC
Asia/TokyoAPAC
Euro/ItalyEU
Europe/LondonEU
Europe/ParisEU
US/EasternAMERICA

 

Thanks,

 

Larry

 

You probably want a switch for something like this. For example,

Region =
VAR Loc = Table1[Location]
RETURN
    SWITCH (
        TRUE (),
        LEFT ( Loc, 7 ) = "America", "AMERICA",
        LEFT ( Loc, 4 ) = "Asia", "APAC",
        LEFT ( Loc, 4 ) = "Euro", "EU",
        LEFT ( Loc, 3 ) = "US/", AMERICA
    )

 

Hi @AlexisOlson ,

 

Cool! It works for me. Thanks a lot for the help.

 

Larry

ValtteriN
Super User
Super User

Hi,

Here is an example:

Category = IF(Category[Name] in {"TABLE","PEN"},"OTHER","FRUIT")
ValtteriN_0-1639638200477.png


I hope this helps to solve your issue and if it does consider accepting this as a solution and giving the post a thumbs up!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ValtteriN ,

 

Great! It works well for me. Thank you for the help😊

 

Larry

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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