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

IF-ELSE

My Input is like so: 

Anonymous__0-1675848515444.png

I need to define 'd', 'e' and 'f' under a singular category and let everything else remain the same. So, somthing like If input is 'a', 'b' and 'c', then no change else mark them as 'h' or If my input is not 'a','b' or 'c', then rename them as 'h'.

Output - 

Anonymous__1-1675848776834.png

 

How do I do this using DAX in an efficient manner? 

 

Thanks for the help!:)

 

P.S: There are many more rows with different that need to be defined under 'h', values for 'a','b' and 'c' are same everywhere. 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Anonymous_ 

try like:

Column = IF ( [ColumName] IN {"a","b","c"}, [ColumName], "h" )

View solution in original post

4 REPLIES 4
BrianConnelly
Resolver III
Resolver III

If statements are good, but dont give you the ability to cleanly expand. I would go with something similiar to Freeman, but as such...

Column = 
SWITCH(TRUE()
, IF ( [ColumName] IN {"a","b","c"}, [ColumName]
, "h" 
)

You can keep adding rules.....

Column = 
SWITCH(TRUE()
, IF ( [ColumName] IN {"a","b","c"}, [ColumName]
, IF ( [ColumName] IN {"e","f"}, "g"
, "h" 
)
Anonymous_
Frequent Visitor

Thank you so much! The solution above worked, the [ColumnName] before, "h" is necessary to complete the query 🙂

FreemanZ
Super User
Super User

hi @Anonymous_ 

try like:

Column = IF ( [ColumName] IN {"a","b","c"}, [ColumName], "h" )

AilleryO
Memorable Member
Memorable Member

Hi,

Not 100% sure of your request but I'll give a try :
Test Column = IF ( [ColumName] IN {"d","e","f"}, "h" )

If you have many tests, you should consider using SWITCH function,

or if you have many many tests, even consider in making a correpondance table and use merge of queries.

Hope it helps, let us know

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.

Top Solution Authors