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
Asuna
Frequent Visitor

How to Find Percentage Based on Another Field Containing a Specific String?

Hello, I was looking for some help as I am quite new to DAX, I was wondering if it is possible to make a column that counts the total number of rows in Batch ID then count the number of instances in the notes column that contains a speific string? I am trying to make a percentage of Batch ID that contains a keyword in the notes. I only want to accomplish this because the batch id is unique and the notes are often duplicated and I need to be able to identify the percentages by method so just counting the notes will not work.

 

Asuna_0-1695127901788.png

 

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

So as far as I understand, Batch column contains unique values and you need pct per Method. Here is the measure:

pct =
VAR method = SELECTEDVALUE ( Table_[Method] )
VAR errorRows =
    CALCULATE (
        COUNT ( Table_[Batch] ),
        CONTAINSSTRING ( Table_[Notes], "Error" ),
        Table_[Method] = method
    )
VAR allRows = CALCULATE ( COUNT ( Table_[Batch] ), Table_[Method] = method )
RETURN
    DIVIDE ( errorRows, allRows, 0 )

ERD_0-1695228936505.png

 

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

You need to do something like this. If this doesn't work, provide more context of your dataset. Happy to help.
Percentage =
VAR _CountRows =
    COUNTROWS ( 'Table' )
RETURN
    DIVIDE (
        _CountRows,
        CALCULATE (
            COUNT ( 'Table'[Method] ),
            ALL ( 'Table' )
        )
    )

Apologies I think my first post was a bit confusing... here is an example of data for it.

Asuna_0-1695226778588.png

And my desired output is a percentage based on the count of total rows in the batch column that has a note containing "Error" allowing you to sort by method as it is attached to the batch column which is always unique unlike notes.

ERD
Community Champion
Community Champion

Hi. Please, provide some demo data and show the desired output.

https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Get-Your-Question-Answered-Qu... 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Asuna
Frequent Visitor

Oops, sorry here is some example data: 
Batch    Method         Notes (String)

1Method1 Correct 07 Jul 2023
2Method1 Correct 11 Aug 2023
3Method2 Correct 11 Aug 2023
4Method1 Correct 19 Sep 2023
5Method1 Error 19 Sep 2023


My desired output would be the ability to identify the rate at which the notes string contains the phrase error.

Method1

 20% Error
Method2 0% Error
ERD
Community Champion
Community Champion

So as far as I understand, Batch column contains unique values and you need pct per Method. Here is the measure:

pct =
VAR method = SELECTEDVALUE ( Table_[Method] )
VAR errorRows =
    CALCULATE (
        COUNT ( Table_[Batch] ),
        CONTAINSSTRING ( Table_[Notes], "Error" ),
        Table_[Method] = method
    )
VAR allRows = CALCULATE ( COUNT ( Table_[Batch] ), Table_[Method] = method )
RETURN
    DIVIDE ( errorRows, allRows, 0 )

ERD_0-1695228936505.png

 

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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