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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
rockingmark
Advocate I
Advocate I

COUNT ROWS WHERE VALUE IN ONE COLUMN, HAS A SPECIFIED STRING IN ANOTHER COLUMN

Trying to count rows in a table and give a measure for how many rows contain the string "Very" in the Description column for each Colour.  Everything I have tried counts the number of rows that have very in the whole table (in this case 6), so the third column in my table is incorrect. The third column used the calculated column:-

COUNTIF COLOUR FOR Very =
COUNTROWS(
    FILTER(
        ALL(Brightness),
        Brightness[Colour] = Brightness[Colour] &&
        CONTAINSSTRING(Brightness[Description ],"Very") = TRUE()
    )
)

 

The last column " Count of "Very" for each colour" is the desired output, which is a count of the number of rows containing "Very" for each colour

 

ColourDescription COUNTIF COLOUR FOR VeryConfirmedCount of "Very" for each colour
BlueVery Dim6Yes1
BlueDim6 1
BlueBright6 1
BlueSlightly Dull 6 1
GreenVery Bright6 2
GreenVery Dim6 2
GreenDim6Yes2
GreenBright6 2
GreenSlightly Dull 6 2
RedVery Bright6 3
RedVery Dim6 3
RedDim6Yes3
RedBright6 3
RedSlightly Very Dull 6 3

 

 

 

 

1 ACCEPTED SOLUTION
v-jialongy-msft
Community Support
Community Support

Thank you for your prompt reply! @parry2k 

 

Hi @rockingmark 

 

Please try the following measure:

Measure = 
VAR _color = SELECTEDVALUE(Brightness[Colour])
RETURN
CALCULATE(COUNTROWS('Brightness'),FILTER(ALL('Brightness'),'Brightness'[Colour]=_color && CONTAINSSTRING('Brightness'[Description],"Very")=TRUE()))

 

This is the result you want:

vjialongymsft_0-1716529379339.png

 

 

 

 

 

Best Regards,

Jayleny

 

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-jialongy-msft
Community Support
Community Support

Thank you for your prompt reply! @parry2k 

 

Hi @rockingmark 

 

Please try the following measure:

Measure = 
VAR _color = SELECTEDVALUE(Brightness[Colour])
RETURN
CALCULATE(COUNTROWS('Brightness'),FILTER(ALL('Brightness'),'Brightness'[Colour]=_color && CONTAINSSTRING('Brightness'[Description],"Very")=TRUE()))

 

This is the result you want:

vjialongymsft_0-1716529379339.png

 

 

 

 

 

Best Regards,

Jayleny

 

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

Many Thanks Jayleny, exactly what I wanted

parry2k
Super User
Super User

@rockingmark if you want to show the count for each row of the color then do this:

 

Very = 
VAR __Color = Color[Colour]
RETURN
CALCULATE ( 
    COUNTROWS ( Color ), 
    FILTER ( 
        ALL ( Color[Colour], Color[Description ] ), 
        Color[Colour] = __Color && 
        CONTAINSSTRING ( Color[Description ], "Very" ) 
    ) 
) 


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi parry2k,
Thanks for this solution. I used it to make a new column (hope that was the intention)
This solution resulted in rows with blank values as shown below. Couldn't understand why, especially as some of the rows that dont have the word "Very" in the description got a count result in the "Very" column and some didnt'.
Could you explain why it worked that way, to help my understanding of dax

I would like all rows for very column very to be populated.

rockingmark_1-1716909147979.png

 

 

 

 

parry2k
Super User
Super User

@rockingmark try this, change the column and table name as per your model

 

Very = 
VAR __Color = Color[Colour]
RETURN
CALCULATE ( COUNTROWS ( Color ), FILTER ( ALL ( Color[Colour] ), Color[Colour] = __Color && CONTAINSSTRING ( Color[Description ], "Very" ) ) ) 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.