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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
LYBridges
Frequent Visitor

DAX returning 2 values when only 1 is selected

This is basically a DAX to abbreviate words to 1 or 2 letters and then list them and eliminate trailing commas.  If only Pre-Risk is selected, it keeps returning "PR,R".  It should just return "PR". 

 

RQDel =
VAR PreRisk = IF(CONTAINSSTRING('Pipeline'[Ops Delegated Services], "Pre-Risk"), "PR", "")
VAR Risk = IF(CONTAINSSTRING('Pipeline'[Ops Delegated Services], "Risk"), "R", "")
VAR Quality = IF(CONTAINSSTRING('Pipeline'[Ops Delegated Services], "Quality"), "Q", "")

RETURN
TRIM (
    IF(PreRisk <> "", PreRisk & IF(Risk <> "" || Quality <> "", ",", ""), "") &
    IF(Risk <> "", Risk & IF(Quality <> "", ",", ""), "") &
    Quality
)
4 REPLIES 4
tamerj1
Super User
Super User

Hi @LYBridges 

Make sure to include a space before and after Risk so it becomes " Risk "

RQDel =
CONCATENATEX (
FILTER (
ADDCOLUMNS (
{ ( 1, "Pre-Risk", "PR" ), ( 2, " Risk ", "R" ), ( 3, "Quality", "Q" ) },
"@Result", IF ( CONTAINSSTRING ( Pipeline[Ops Delegated Services], [Value2] ), [Value3] )
),
NOT ISBLANK ( [@Result] )
),
[@Result],
",",
[Value1], ASC
)

techies
Resolver II
Resolver II

Hi @LYBridges please  check this

VAR PreRisk = IF(EXACT('Pipeline'[Ops Delegated Services], "Pre-Risk"), "PR", "")
VAR Risk = IF(CONTAINSSTRING('Pipeline'[Ops Delegated Services], "Risk") && NOT CONTAINSSTRING('Pipeline'[Ops Delegated Services], "Pre-Risk"), "R", "")
VAR Quality = IF(CONTAINSSTRING('Pipeline'[Ops Delegated Services], "Quality"), "Q", "")

RETURN
TRIM (
    IF(PreRisk <> "", PreRisk & IF(Risk <> "" || Quality <> "", ",", ""), "") &
    IF(Risk <> "", Risk & IF(Quality <> "", ",", ""), "") &
    Quality
)

I spoke too soon. This now returns too few values.

Incorrect returned value - 

If the source coulmn has all 3, it is only returning Q.

If the source column has Pre-Risk and Risk, it returns no abbreviation. 

 

Correct return values 

If the source column has Risk and Quality, it correctly returns R,Q. 

If the source column has Pre-Risk, it correctly returns PR. 

If the source column has Risk, it correctly returns R. 

 

I have a multi-select/mulit-choice column that can have any combination of 18 different choices. 

For the new column/DAX I'm trying to create, we are only interested in the choices Pre-Risk, Risk and/or Quality.

For each row, we want to know which one or which combination of choices were selected. Due to limited space, we are trimming down to just abbreviations (PR, R, Q).

 

So the new column will have one or any combination of PR, R, Q displayed based on the multi-select column in the source. 

Greg_Deckler
Super User
Super User

@LYBridges Well, yeah, because "Pre-Risk" also contains the word "Risk" so that's the logical outcome of what you have coded. The real question, what do you actually expect the output to be and can you provide sample data? 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements