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
a3810
New Member

Calculating a ratio based on partial text values

Sorry if this question seems too simple, but I am looking for a way to insert a quick measure which calculates the ratio of certain values.
 
Worker
Service
Cost
James
Initial service
$1
Harry
Initial service
$2
Steve
Review
$2
Harry
Review Comp
$0
Steve
Initial Appointment
$3
James
Review
$2
Steve
Initial Consult
$5
James
Review
$2
James
Review > 7
$3
Steve
Initial Comp
$4
Steve
Initial 
$3
 
I want to count all services that include the term 'Initial' and divide by the number of total Services for a worker, ie calculate the ratio of services that are 'Initial' compared with the workers total services. 
 
I can filter to count the number containing 'Initial' but not then link to the total number for a worker. Can anyone assist? 
 
1 ACCEPTED SOLUTION

Share the download link of the PBI file with the 3 visuals already built there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

12 REPLIES 12
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1712203133769.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

This is really helpful.

 

When i run the Is the Service Initial measure, I get the error:

 

A single value for column 'Item' in table 'Master Activity Report' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result. 

 

Could it be because my service value descriptions are long. Here is an example:

 

a3810_0-1712204821693.png

 

I do not know the reason.  Review my solution carefully and retry.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Sorry, you are correct. It was an error at my end. 

 

However, when I look at my data, the number is Is my service initial? calculation is less then if I run a filter manually, selecting only those services which have the term initial. This is not doing a distinct count is it?

 

Really appreciate your help. 

I do not understand your question.  Based on the Table that you shared in the first post, show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

a3810_0-1712209758237.png

Sorry if I was unclear. 

 

The table on the far left is from manually filtering the data to select only items with the term initial used. 

The middle table is the total number of items per person. 

The one on the right is using your code to create a new measure. Given the difference, could your code be counting only distinct codes which contain the word 'initial'?

 

I would just use the filtered number, but I need Power Bi to do the calculation automatically, hence the need for a new measure. 

 

Sorry to keep coming back to you. I know this is proabaly a really easy issue that I am just not understanding. 

Share the download link of the PBI file with the 3 visuals already built there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks so much Ashish! Your solution has helped me so much!!

 

Really appreciate your time and expertise!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@a3810 , based on what I got

 

Divide(

Calculate( Sum(Table[Cost]), filter(Table, containsstring(Table[Service],"Initial"))) , Sum(Table[Cost]) )

 

or

 

Divide(

Calculate( Count(Table[Service]), filter(Table, containsstring(Table[Service],"Initial"))) , Count(Table[Service]) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

And when I try:

 

Measure 2 = Divide(

Calculate( Sum('Master Activity Report'[Item]), filter('Master Activity Report', containsstring('Master Activity Report'[Item],"Initial"))) , Sum('Master Activity Report'[Item]) )
 
It gives a red error over "Initial"
 
The word initial is part of the code description. Should it start with an * as it is a partial match?
 
Thanks again. 

Thanks Amit.

 

I have used the second option, however I get the error saying that 'To use special characters in a measure, enclose the entire name in brackets ( [] ) and add a ] to any closing brackets in the name. 

 

Is the issue in my table or sheet names? Here is my input.

 

Divide(

Calculate( Count(Master Activity Report[Item]), filter(Master Activity Report, containsstring(Master Activity Report[Item],"Initial"))) , CountMaster Activity Report[Item]) )

 

Thanks so much for your response. 

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.