Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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, Opening, Issue Description, Issue Description, Opening, Opening, Issue Resolution, Issue Description, Close, Close, Issue Description, Close"
2) I want to end up with a simplified sequence by consolidating identical consecutive substrings. I.e, instead of the string above i would end up with this:
"Opening, Issue Description, Opening, Issue Resolution, Issue Description, Close, Issue Description, Close"
I'm operating on a very large dataset so performance is going to be key.
Honestly not sure where to even begin so any pointers would be appreciated.
Thank you
Hi @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
you want to use CONCATENATX and DISTINCT
this post has some explanation https://community.powerbi.com/t5/Desktop/Concatenatex-related-distinct-values/td-p/337412
I'm a personal Power Bi Trainer I learn something every time I answer a question
The Golden Rules for Power BI
Help when you know. Ask when you don't!
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
11 | |
9 | |
6 |