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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
JensHN
Frequent Visitor

Count rows containing different specifc text

Hi,

 

my datamodel contains two tables. First table is "Jobs" with an "Attributes" filed:

 jobs-table.jpg 

Second table is "Attribute" with a "Name" filed.

attributes-table.jpg

 

There is no connection between these tables. Important thing: The Jobs[Attributes] field does not contain the exact same values like Attribute[Name]. For example, the Attribute table has the value "Christmas", the Jobs table has values like "Christmas 2017", "Christmas 2018", etc.

 

What i need is the amount of jobs for each attribute. For the sample data the result should look like this:

result.jpg

 

I tried a calculated column on the Attribute table, but I only got an error:

AmountJobs = CALCULATE(COUNTROWS(Jobs); SEARCH(Attribute[Name]; Jobs[Attributes]))

 

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

this will work

Measure = 
VAR _Attribute = SELECTEDVALUE(Attribute[Name],BLANK())
VAR _SearchFlag = ADDCOLUMNS(Jobs,"Flag",SEARCH(_Attribute,Jobs[Attributes],1,BLANK()))
VAR _RelevantRows = FILTER(_SearchFlag,[Flag]<>BLANK()) 
RETURN
COUNTROWS(_RelevantRows)

you need to use Name from Attribute table and measure in the visual, there should be no joins between the tables
it does the job, but search will affect the performance badly (it has to iterate every string in the Jobs table), so the performance may not be great for bigger datasets



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

3 REPLIES 3
Stachu
Community Champion
Community Champion

this will work

Measure = 
VAR _Attribute = SELECTEDVALUE(Attribute[Name],BLANK())
VAR _SearchFlag = ADDCOLUMNS(Jobs,"Flag",SEARCH(_Attribute,Jobs[Attributes],1,BLANK()))
VAR _RelevantRows = FILTER(_SearchFlag,[Flag]<>BLANK()) 
RETURN
COUNTROWS(_RelevantRows)

you need to use Name from Attribute table and measure in the visual, there should be no joins between the tables
it does the job, but search will affect the performance badly (it has to iterate every string in the Jobs table), so the performance may not be great for bigger datasets



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

JensHN
Frequent Visitor

Thank you for your fast solution, this works well.

Would it be better for the performance when the amount of jobs is a calculated column in the Attribute table?

Stachu
Community Champion
Community Champion

does it perform badly now? if you're fine with performance then I would keep it as is

The problem with precalculating columns in the table is following: you would have to do it for each event, so Christmas, New Year, and Easter separately, and additional one for every single new event. You cannot have calculated column that's dependant on the slicer value, although it does work nicely as variable (cause it's always single value in the filter context of the visual, i.e. for Christmas column in the chart I only calculate Christmas)

 

I think the most performant solution would be changing the Jobs table to something like this:

IDAttributeYear
1Christmas2017
2Christmas2017
2New Year2017
3New Year2018
3Easter2018

then you can just do simple row count of unique IDs per Attributes

transformation could be done in M, assuming the naming conventions is always "eventname YYYY"



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors