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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare 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
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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