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
kbraga
Helper I
Helper I

Calculated Column with nesting IF, THEN statements

I think this is real simple but I can't seem to figure it out. I have one column with a list of text values and based on those values, I want a certin numeric value to appear in a new calculated column. Below is an example: 

 

Likert ScaleAssociated Value 
Strongly Disagree

1

Disagree

2
Neutral3
Agree4
Strongly Agree5
NA6

 

What is the DAX formula to get the associated value to appear based on the text in the likert scale column? 

1 ACCEPTED SOLUTION
kbraga
Helper I
Helper I

Found a solution:

 

Likert Sort Value =
SWITCH (
TRUE (),
'Survey Response'[Text] = "Strongly Disagree", "1",
'Survey Response'[Text] = "Disagree", "2",
'Survey Response'[Text] = "Neutral", "3",
'Survey Response'[Text] = "Agree", "4",
'Survey Response'[Text] = "Strongly Agree", "5",
'Survey Response'[Text] = "NA", "6",
"0"
)

View solution in original post

3 REPLIES 3
kbraga
Helper I
Helper I

Found a solution:

 

Likert Sort Value =
SWITCH (
TRUE (),
'Survey Response'[Text] = "Strongly Disagree", "1",
'Survey Response'[Text] = "Disagree", "2",
'Survey Response'[Text] = "Neutral", "3",
'Survey Response'[Text] = "Agree", "4",
'Survey Response'[Text] = "Strongly Agree", "5",
'Survey Response'[Text] = "NA", "6",
"0"
)
kentyler
Solution Sage
Solution Sage

Evaluates an expression against a list of values and returns one of multiple possible result expressions.

Syntax

DAX
SWITCH(<expression>, <value>, <result>[, <value>, <result>]…[, <else>])  

Parameters

PARAMETERS
Term Definition
expression Any DAX expression that returns a single scalar value, where the expression is to be evaluated multiple times (for each row/context).
value A constant value to be matched with the results of expression.
result Any scalar expression to be evaluated if the results of expression match the corresponding value.
else Any scalar expression to be evaluated if the result of expression doesn't match any of the value arguments.

Return value

 

But you might also consider creating a dimension table that had the text values in one column and the numeric values in the other. If you relate the dimension table to your fact table you will get direct access to the numeric value thru the relationship.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


az38
Community Champion
Community Champion

Hi @kbraga 

If I understand you correct try SWITCH, like

Associated Value = 
SWITCH(Table[Likert Scale],
"Strongly Disagree", 1,
"Disagree", 2,
"Neutral", 3,
"Agree", 4,
"Strongly Agree", 5,
6
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.