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

Create Column based on Values?

I want to create a new column where if Table[Animal] is equal to "Cat", "Dog", "Horse" assign "Four Legs" and for all other values, assign "Other"

 

What would the DAX look like?

So far I have:

 

Legs = 
SWITCH(
    TRUE (),
    'Table'[Animals] = "Cat", "4 Legs",
    'Table'[Animals] = "Dog", "4 Legs",
    'Table'[Animals] = "Horse", "4 Legs"
)

 

1 ACCEPTED SOLUTION

You can Another IF or use Switch like this:

Legs =
SWITCH (
    TRUE (),
    'Table'[Animals] = "Cat", "4 Legs",
    'Table'[Animals] = "Dog", "4 Legs",
    'Table'[Animals] = "Horse", "4 Legs",
    'Table'[Animals] = "New Condition", "Result",
    "Other"
)

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

View solution in original post

5 REPLIES 5
olgad
Super User
Super User

Hi, 

olgad_0-1674604227175.png

But i would always recommend to have an index and use that.

Legs =
SWITCH('Table'[Index],
    1,  "4 Legs",
    2,  "4 Legs",
    3, "4 Legs",
    "Other"
)
olgad_1-1674604416233.png

 


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime
VahidDM
Super User
Super User

HI @powerbinoobster 

 

Try this:

Legs = 
IF('Table'[Animals] in {"Cat","Dog","Horse"}, "4 Legs", "Other")

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

what if I have other conditons that I want to assign a specific value before I assign all remaining to "Other".

if condition 1:
  assign value 1
else if condition 2:
  assign value 2
else:
  assign value 3

You can Another IF or use Switch like this:

Legs =
SWITCH (
    TRUE (),
    'Table'[Animals] = "Cat", "4 Legs",
    'Table'[Animals] = "Dog", "4 Legs",
    'Table'[Animals] = "Horse", "4 Legs",
    'Table'[Animals] = "New Condition", "Result",
    "Other"
)

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

Anonymous
Not applicable

@VahidDM is it possible to add another column value to look to determine the outcome using what you have on this topic?

 

jrmaier_0-1679337806004.png

I have two possible values for the Class Name column based on the Course Name and whether a student is in 7 or 8 grade.

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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.