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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.