Forum Discussion
bmk
3 years agoHelper II
Extract n words from string
Hello, I wish to extract certain number of words from the beginning of a sentence based on a delimiter, space character being the most generic. Example : "word1 word2 word3 word4 word5" Output (...
- 3 years ago
bmk
Sorry for the the late reply. Please refer to attached sample file, I hope this is what you're looking for.Output = VAR N = MAX ( Selection[Last n Words] ) VAR String = SELECTEDVALUE ( 'Table'[Column] ) VAR Items = SUBSTITUTE ( String, " ", "|" ) VAR Length = COALESCE ( PATHLENGTH ( Items ), 1 ) VAR T1 = GENERATESERIES ( 1, Length, 1 ) VAR T2 = ADDCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) ) VAR T3 = FILTER ( T2, [Value] <= N ) RETURN CONCATENATEX ( T3, [@Item], " ", [Value], ASC )
tamerj1
3 years agoCommunity Champion
bmk
Sorry for the the late reply. Please refer to attached sample file, I hope this is what you're looking for.
Output =
VAR N = MAX ( Selection[Last n Words] )
VAR String = SELECTEDVALUE ( 'Table'[Column] )
VAR Items = SUBSTITUTE ( String, " ", "|" )
VAR Length = COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T1 = GENERATESERIES ( 1, Length, 1 )
VAR T2 = ADDCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) )
VAR T3 = FILTER ( T2, [Value] <= N )
RETURN
CONCATENATEX ( T3, [@Item], " ", [Value], ASC )tamerj1
3 years agoCommunity Champion
bmk
The following code returns the full text incase there is no selection or if multiple items are selected
Output =
VAR String = SELECTEDVALUE ( 'Table'[Column] )
VAR Items = SUBSTITUTE ( String, " ", "|" )
VAR Length = COALESCE ( PATHLENGTH ( Items ), 1 )
VAR N = SELECTEDVALUE ( Selection[Last n Words], Length )
VAR T1 = GENERATESERIES ( 1, Length, 1 )
VAR T2 = ADDCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) )
VAR T3 = FILTER ( T2, [Value] <= N )
RETURN
CONCATENATEX ( T3, [@Item], " ", [Value], ASC )