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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Flossiebug
New Member

Power BI - way to count rows based on conditional formatting

Hi all - I'm currently trying to develop a simple dashboard for use at work in my NHS department. 

 

I have a table of reasons for cancellations - so it's free text format. I've applied conditional formatting to identify particular reasons, such as illness, or medication issues which colours things a certain colour based on reason. 

 

What I'd really like to do is to be able to add a card or filter which will show me a quantitative value for each reason - so all those identified as being due to the patient being unwell, which conditional formatting has coloured grey, is counted as a number and displayed on a card.

 

Is this something which is achievable? I'm very new to Power BI so have been drowning in Google and videos trying to find a solution!!

1 ACCEPTED SOLUTION
mdaatifraza5556
Super User
Super User

Hi @Flossiebug 


As per my understanding of you requirement i have tried using below dax.

1. Create a calculated column using below dax ( If you want to add some more condition then you can in to that).

CancellationCategory =
SWITCH(TRUE(),
    SEARCH("ill", 'Table'[Reason], 1, 0) > 0, "Illness",
    SEARCH("medication", 'Table'[Reason], 1, 0) > 0, "Medication Issue",
    "Other"
)
 
Screenshot 2025-07-30 173623.png

 

2. Create measure and then add that measure into the card and the calculated column use it as a slicer.
------> Use below dax to create dax which calculate as per the slicer.

 

Count =
COUNTROWS('Table')


Screenshot 2025-07-30 173923.png

 

Screenshot 2025-07-30 173927.png

 


If this answers your questions, kindly accept it as a solution and give kudos.

View solution in original post

8 REPLIES 8
mdaatifraza5556
Super User
Super User

Hi @Flossiebug 


As per my understanding of you requirement i have tried using below dax.

1. Create a calculated column using below dax ( If you want to add some more condition then you can in to that).

CancellationCategory =
SWITCH(TRUE(),
    SEARCH("ill", 'Table'[Reason], 1, 0) > 0, "Illness",
    SEARCH("medication", 'Table'[Reason], 1, 0) > 0, "Medication Issue",
    "Other"
)
 
Screenshot 2025-07-30 173623.png

 

2. Create measure and then add that measure into the card and the calculated column use it as a slicer.
------> Use below dax to create dax which calculate as per the slicer.

 

Count =
COUNTROWS('Table')


Screenshot 2025-07-30 173923.png

 

Screenshot 2025-07-30 173927.png

 


If this answers your questions, kindly accept it as a solution and give kudos.

Oh wow - thank you so much! I've tried your ideas and it has done exactly what I was looking for, thank you so so much. I'm loving finding out what I can do with Power BI and am really grateful to you for taking the time to explain it all so clearly. 

FBergamaschi
Solution Sage
Solution Sage

It is feasible, pls provide tables 

 

Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

 

Need help uploading data? click here

 

Want faster answers? click here

Hi - thanks for your answer - I will include more info next time as an example, making sure to keep it anonymised.

jaineshp
Memorable Member
Memorable Member

Hi @Flossiebug,

You can try this approach to resolve the same:

Create measures instead of relying on conditional formatting:

Step 1: Create a calculated column or measure that categorizes your reasons

Reason Category =
SWITCH(TRUE(),
CONTAINSSTRING([Cancellation Reason], "illness"), "Patient Unwell",
CONTAINSSTRING([Cancellation Reason], "unwell"), "Patient Unwell",
CONTAINSSTRING([Cancellation Reason], "medication"), "Medication Issues",
"Other"
)
Step 2: Create count measures for each category

Patient Unwell Count =
CALCULATE(COUNTROWS(YourTable), [Reason Category] = "Patient Unwell")

Step 3:
Add these measures to card visuals on your dashboard

Step 4: Use the same logic in your conditional formatting so colors match your counts
Alternative quick approach:

  • Create a slicer with your new "Reason Category" column
  • Use a simple COUNTROWS measure that responds to the slicer selection
  • This gives you both filtering capability and count display

The key is moving away from conditional formatting as your source of truth and creating proper categorization logic that both your formatting and counting can reference.

Works much better than trying to count based on colors!

Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Hi - thanks so much for your ideas, I have ended up removing the conditional formatting as I much prefer the new column creating measure to categorise responses and it is definitely much easier than counting the colours! Feeling very new to all this, but learning so much! Thanks again.

bhanu_gautam
Super User
Super User

@Flossiebug Create a new measure in Power BI that counts the number of cancellations for a specific reason. You can use the DAX COUNTROWS function combined with a FILTER function to achieve this. 

 

Illness Cancellations = COUNTROWS(FILTER('YourTableName', 'YourTableName'[CancellationReason] = "Illness"))

 

Once you have created measures for each reason, you can add a card visualization to your Power BI report canvas. Drag the measure you created (e.g., Illness Cancellations) to the "Values" field of the card visualization to display the quantitative value for each reason.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi - thanks for your response. I've gone with a different solution, but can see how yours would help too. Thanks so much for your time and reply.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.