Forum Discussion
String Count with loop in each row
Hi Power BI master around the world,
I have been so active recently because getting interested with this DAX. I have a very difficult measure that i am not sure if it is possible to do in Power BI.
Let say i have this table
| Column Name |
| Hydrogenxxx, Lithiumyyy, Natriumzzz |
| Hydrogenaaa, Natriumbbb, Natriumccc |
| Hydrogenaaa |
| Lithium<ddd |
| Natriumccc |
| Natriumeee |
| Lithiumfff |
So there are blank rows.
I would like to identify how many times occurence of Natrium in this column.
1st row : 1
2nd row : 2
6th row : 1
7th row : 1
There is "," (comma) delimeter between each string.
Any idea? Thanks
Hi dannytan1112
Please refer to attached sample file with the solutionCount = VAR CurrentElelent = SELECTEDVALUE ( Elements[Element] ) RETURN SUMX ( VALUES ( 'Table'[Column Name] ), VAR String = 'Table'[Column Name] VAR Items = SUBSTITUTE ( String, ", ", "|" ) VAR Length = PATHLENGTH ( Items ) VAR T1 = GENERATESERIES ( 1, Length, 1 ) VAR T2 = SELECTCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) ) VAR T3 = FILTER ( T2, CONTAINSSTRING ( [@Item], CurrentElelent ) ) RETURN COUNTROWS ( T3 ) )
9 Replies
- tamerj1Community Champion
Hi dannytan1112
Please refer to attached sample file with the solutionCount = VAR CurrentElelent = SELECTEDVALUE ( Elements[Element] ) RETURN SUMX ( VALUES ( 'Table'[Column Name] ), VAR String = 'Table'[Column Name] VAR Items = SUBSTITUTE ( String, ", ", "|" ) VAR Length = PATHLENGTH ( Items ) VAR T1 = GENERATESERIES ( 1, Length, 1 ) VAR T2 = SELECTCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) ) VAR T3 = FILTER ( T2, CONTAINSSTRING ( [@Item], CurrentElelent ) ) RETURN COUNTROWS ( T3 ) )- ItsbibinRegular Visitor
Hi tamerj1
Ihave 2 table in my Power BI report B-Details and SPResult. SP result table is a stored procedure and will change dynamically with parameters. I want to create a new table from this in which it should filter Name and Country from B-Details and SPResult. Now after filtering this we have a uniquekey in B-Details. Now in the new table for each UniqueKey we have to get all the filtered values from SPResult table. So in the new table UniqueKey key row will be duplicated with as much rows we have in SPResult. Can you help me how to fix this?
- Mahesh0016Super User
*If this post helps, please consider accept as solution to help other members find it more quickly and Appreciate your Kudos.
- FreemanZSuper User
hi dannytan1112
you may also create a column like this:
COUNT = (LEN([Column Name]) - LEN(SUBSTITUTE([Column Name], "Natrium", "")))/7tried and it worked like this: