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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Daniel_B
Helper II
Helper II

Calculate Average if row contains text but with an exclusion

Hi Again

 

This challenge has me beat as I can calculate averages where 2 basic criteria are needed but my new challenge is;

 

To create a measure that calculates a total average score for where every row that contains the text "OX" but not "LOX" 

 

The columns are

 

Name: This one will contain the items which will have "OX" and "LOX" within the text string (example - Oxtail, Oxford, Loxing)

Score: This will have a value from 1 - 5 as a score and only 1 score per row

 

I'm pretty stumped as I don't really know how to look for parts of text strings to search for those matches

 

Again, any code/links/videos etc with examples of this would be great

 

Thanks


Dan_B

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

 
You can refer to this DAX
Measure2 = 
CALCULATE(
    AVERAGE('Table'[score])
    , FILTER(
        'Table' 
        , LEFT('Table'[name] , 2) IN {"Ox"})
)​
Here is the .pbix
 
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
V-lianl-msft
Community Support
Community Support

 
You can also add a conditional column in edit query.
 
test_conditional column.PNGtest_measure.PNG
 
 
 
 
 
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
V-lianl-msft
Community Support
Community Support

Hi @Daniel_B ,

 

Is this problem sloved? If not, please let me know.

 

Best Regards,

Liang

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

V-lianl-msft
Community Support
Community Support

 
You can refer to this DAX
Measure2 = 
CALCULATE(
    AVERAGE('Table'[score])
    , FILTER(
        'Table' 
        , LEFT('Table'[name] , 2) IN {"Ox"})
)​
Here is the .pbix
 
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
jdbuchanan71
Super User
Super User

Hello @Daniel_B 

You can use CONTAINSSTRING to check for that so something like this:

Measure = 
CALCULATE( AVERAGE( Scores[Score] ),
    CONTAINSSTRING ( Scores[Name],"OX" ),
    NOT ( CONTAINSSTRING ( Scores[Name], "LOX" ) )
)

 

Hi @jdbuchanan71 

 

I tried that but when I try to add the measure to a scorecard it only "Can't Display the Visual" or BLANK even though there are lines that contain Ox somewhere within the string

 

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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