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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Lobo1908
Helper I
Helper I

Count rows with additional values in the string

Hi, 

I'm looking for a measure that would allow me to count rows with some values in the string. 

I've got a table with a column serial numbers and a column with codes assigned to those serial numbers. 

The measure should count only the rows if in that row there is a code different to "Q0001".

Now if a row has a code for e.g. "Q0002" and code "Q0001" this should also be taken into the count.

The additional, issue I have with my data is that the values in the string are not clean.

What I mean by that is some of them are like " Q0001" or " Q0001       "

Additionally, there are some values in the string like "Q 188" which must be ignored. 

Only values in the format QNNNN are acceptable.

 

 

Please find below an example of my data.

The result for this data should be 10.

 

I've also attached a simplyfied report in the link :

https://drive.google.com/file/d/114Jn58-yxf0ZpwiMlLqEQx9tAp1tWF68/view?usp=share_link

 

SerialQ Codes
123Q0001
124 Q0001
125Q0003
126Q0004
127Q0005
9Q0003 Q0001
10Q0003 Q0002 Q0001
11Q0003 Q0001 Q0002
12Q0003Q0001 Q0002
13Q0001
14Q0001    
15Q0001
16Q0001 Q 222
17Q 188 Q0001
444Q0001 Q0001
443Q0023 Q0042
442Q0033 Q0102
441Q0001
440Q0999 Q0002
1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @Lobo1908 

 

Please try the following

CountWIhtouQ0001 = 
SUMX(
    VALUES('Table'[Serial]),
    IF(
        CONCATENATEX(
            'Table',
            TRIM(SUBSTITUTE([Q Codes],"Q0001",""))
        )
        <>"",1,0
    )
)
    

 

Mikelytics_0-1671462208894.png

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

1 REPLY 1
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @Lobo1908 

 

Please try the following

CountWIhtouQ0001 = 
SUMX(
    VALUES('Table'[Serial]),
    IF(
        CONCATENATEX(
            'Table',
            TRIM(SUBSTITUTE([Q Codes],"Q0001",""))
        )
        <>"",1,0
    )
)
    

 

Mikelytics_0-1671462208894.png

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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