Forum Discussion
DAX function to search for multiple values in strings and count the number of times each value occur
- 5 years ago
Hi GSTI08 ,
It is suggested to create another region table by DAX or just enter data.
Region = DATATABLE ( "Region", STRING, { { "Africa" }, { "South America" }, { "ME" }, { "North America" }, { "UKI" }, { "Europe" } } )Then, create measures like what Greg_Deckler provided.
4 CalcRegion = VAR __SearchTerms = ADDCOLUMNS ( Regions, "Count", COUNTROWS ( FILTER ( 'Accounts', FIND ( [Region], 'Accounts'[Primary Connectivity Regions],, 0 ) > 0 ) ) ) RETURN SUMX ( __SearchTerms, [Count] )Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
GSTI08 Your DAX formula could be greatly simplified:
4 CalcRegion =
VAR __SearchTerms =
ADDCOLUMNS(
{ "Africa", "South America", "ME", "North America", "UKI", "Europe" },
"Count", COUNTROWS(FILTER('Accounts',FIND([Value],'Accounts'[Primary Connectivity Regions],,0)>0))
RETURN
SUMX(__SearchTerms,[Count])
Hi Greg,
That looks much better, thank you. Although I am getting a "The Syntax for 'RETURN' is incorrect, but I can't see why, it looks fine. Any ideas?
Thanks
- Fowmy5 years agoSuper User
GSTI08
Add a closing bracket ")" to Greg_Deckler 's formula before the RETURN as below.4 CalcRegion = VAR __SearchTerms = ADDCOLUMNS( { "Africa", "South America", "ME", "North America", "UKI", "Europe" }, "Count", COUNTROWS(FILTER('Accounts',FIND([Value],'Accounts'[Primary Connectivity Regions],,0)>0)) ) RETURN SUMX(__SearchTerms,[Count])________________________
If my answer was helpful, please consider Accept it as the solution to help the other members find it
Click on the Thumbs-Up icon if you like this reply 🙂