Forum Discussion
Anonymous
6 years agoNot applicable
Help with string consolidation in DAX.
Hello, I need help figuring out how to accomplish the following using DAX: 1) I have a measure that concatenates strings and produces something like this for example: "Opening, Opening, O...
OwenAuger
Super User
6 years agoHi Anonymous
This post from Phil_Seamark provides the starting point for solving this.
If your existing measure is a text string delimited by " ," (space comma), then you could write another measure like this:
Simplified Sequence =
VAR SplitByCharacter = ", "
VAR MyText = <EXISTING SEQUENCE MEASURE>
VAR PositionItem =
VAR PipeDelimited =
SUBSTITUTE ( MyText, SplitByCharacter, "|" )
VAR Length =
PATHLENGTH ( PipeDelimited )
VAR Positions =
SELECTCOLUMNS ( GENERATESERIES ( 1, Length ), "Position", [Value] )
RETURN
GENERATE (
Positions,
VAR CurrentItem =
PATHITEM ( PipeDelimited, [Position] )
VAR PreviousItem =
PATHITEM ( PipeDelimited, [Position] - 1 )
RETURN
FILTER ( { CurrentItem }, [Value] <> PreviousItem )
)
RETURN
CONCATENATEX ( PositionItem, [Value], SplitByCharacter, [Position] )
It makes use of PATH functions to extract the items from the text.
Also I used FILTER to remove consecutive duplicates.
Regards,
Owen