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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
)
1 ACCEPTED SOLUTION

This is the solution that finally worked - 

 

RQDel =
SWITCH(
    TRUE(),
    CONTAINSSTRING('Pipeline'[Delegated Services], "Pre-Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Quality"), "PR, R, Q",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Pre-Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Quality"), "PR, Q",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Pre-Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Risk"), "PR, R",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Quality"), "R, Q",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Pre-Risk"), "PR",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Risk"), "R",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Quality"), "Q",
         "")

View solution in original post

12 REPLIES 12
v-hashadapu
Community Support
Community Support

Hi @LYBridges , Please let us know if your issue is solved. If it is, consider marking the answer that helped 'Accept as Solution', so others with similar queries can find it easily. If not, please share the details.
Thank you.

v-hashadapu
Community Support
Community Support

Hi @LYBridges , Thank you for reaching out to the Microsoft Community Forum.

Please let us know if your issue is solved. If it is, consider marking the answers that helped 'Accept as Solution', so others with similar queries can find them easily. If not, please share the details.
Thank you.

This is the solution that finally worked - 

 

RQDel =
SWITCH(
    TRUE(),
    CONTAINSSTRING('Pipeline'[Delegated Services], "Pre-Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Quality"), "PR, R, Q",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Pre-Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Quality"), "PR, Q",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Pre-Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Risk"), "PR, R",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Risk") && CONTAINSSTRING('Pipeline'[Delegated Services], ", Quality"), "R, Q",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Pre-Risk"), "PR",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Risk"), "R",
    CONTAINSSTRING('Pipeline'[Delegated Services], "Quality"), "Q",
         "")

Hi @LYBridges , Thanks for the update. We are happy to hear that you have resolved the issue. Thanks for sharing the details here. Please mark your insights 'Accept as solution' to help others with similar problems find it easily. 
Thank you.

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
)

Thanks for a new take on this!

 

I tried it out and these are the results based on what is currently in the data source. 

Correct returned values - 

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

 

Incorrect returned vaules - 

If the source coulmn has all 3, it returns only PR,Q.

If the source column has Pre-Risk and Risk, it returns only PR

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

If the source column has Risk, it returns a blank. 

 

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. 

@LYBridges 

Depending on how Risk is written in the source. It might be " Risk" or " Risk,". This is something you can find out by looking at some values of the source column. 

It shows up as " Risk,".

I'll try that.

 

Thanks so much. Love the approach. 

techies
Super User
Super User

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
)
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

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. 

Hi @LYBridges please check this then

 

VAR TextValue = 'Table'[Ops Delegated Services]
VAR PreRiskExists = SEARCH("Pre-Risk", TextValue, 1, 0) > 0
VAR RiskExists = SEARCH(" Risk", " " & TextValue & " ", 1, 0) > 0
VAR QualityExists = SEARCH("Quality", TextValue, 1, 0) > 0
VAR PreRisk = IF(PreRiskExists, "PR", "")
VAR Risk = IF(RiskExists, "R", "")
VAR Quality = IF(QualityExists, "Q", "")

RETURN
TRIM(
    CONCATENATEX(
        FILTER(
            { PreRisk, Risk, Quality },
            NOT(ISBLANK([Value])) && [Value] <> ""
        ),
        [Value],
        ","
    )
)
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978
Greg_Deckler
Community Champion
Community Champion

@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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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