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
Niiru
Regular Visitor

DAX Starts with "String" with a SWITCH statement

I currently have a SWITCH statement that looks for specific text and returns "Yes", "No" and this works fine. However, in addition to this I need to now add in another variable for:

 

Values that begin with "No harm sustained"......

 

I know I have to follow something like this:

 

if(left('Incidents'[Actual severity of impact],17) = "No harm sustained","Yes","No")

OR

VAR result1 = IF(LEFT(MIN(Incidents[Actual severity of impact],17) = "No harm sustained"), "Yes",resul

 

but I feel this will override my current measure.

 

My question is: is there a way to have my SWITCH statement (below) and also a LEFT statement for strings begining with "No harm sustained"?

 

 

Incidents[No harm / No Loss] =

VAR F_sp = SELECTEDVALUE('Reporting Period Filter'[RK_ReportingPeriod],MAX('Reporting Period Filter'[RK_ReportingPeriod]))
VAR F_rp = SELECTEDVALUE('ReportingPeriod'[RK_ReportingPeriod],F_sp)
VAR result = SWITCH(
SELECTEDVALUE('Incidents'[Actual severity of impact]),
"Air quality Monitoring not in line but no harm", "Yes",
"Breach of soil management requirements not resulting in damage", "Yes",
"No"
)

RETURN CALCULATE(result, KEEPFILTERS(ReportingPeriod[RK_ReportingPeriod] <= F_sp ), KEEPFILTERS(ReportingPeriod[RK_ReportingPeriod] = F_rp ))

 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

 

VAR result = SWITCH(TRUE()
SELECTEDVALUE('Incidents'[Actual severity of impact])="Air quality Monitoring not in line but no harm", "Yes",
SELECTEDVALUE('Incidents'[Actual severity of impact])="Breach of soil management requirements not resulting in damage", "Yes",
SEARCH("No harm sustained", SELECTEDVALUE('Incidents'[Actual severity of impact]),1,0)=1,"Yes",
"No"
)

 

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

 

VAR result = SWITCH(TRUE()
SELECTEDVALUE('Incidents'[Actual severity of impact])="Air quality Monitoring not in line but no harm", "Yes",
SELECTEDVALUE('Incidents'[Actual severity of impact])="Breach of soil management requirements not resulting in damage", "Yes",
SEARCH("No harm sustained", SELECTEDVALUE('Incidents'[Actual severity of impact]),1,0)=1,"Yes",
"No"
)

 

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.