חִידָה
חִידָה

Reputation: 279

DAX Power BI occurrences of character in string

-- my DAX formula is unable to count the occurrences of a "," (comma) in a string from Column2, in a specific "Category" row. --

Formula = CALCULATE( COUNTAX( FILTER ('Query1', 'Query1'[Col1] = "Category", 'Query1'[Col2] = ",") ) )

-- Any suggestions? --

Upvotes: 4

Views: 21076

Answers (2)

StelioK
StelioK

Reputation: 1781

This should do the trick without the need of a calculated column

Formula :=
CALCULATE (
    COUNTROWS ( FILTER ( 'Query1', FIND ( ",", 'Query1'[Col1],, 0 ) > 0 ) ),
    'Query1'[Col2] = "Category"
)

Upvotes: 0

CR7SMS
CR7SMS

Reputation: 2584

You can use the following coulmn calculation to count the number of comma in a string:

Check = LEN(Query1[Col2])-LEN(SUBSTITUTE(Query1[Col2],",",""))

If you need the overall count, you can simply sum up the calculated field. Hope this helps.

Upvotes: 8

Related Questions