Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not 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, 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

2 REPLIES 2
OwenAuger
Super User
Super User

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


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
kentyler
Solution Sage
Solution Sage

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

  1. Use a Calendar table. A custom Date tables is preferable to using the automatic date/time handling capabilities of Power BI. https://www.youtube.com/watch?v=FxiAYGbCfAQ
  2. Build your data model as a Star Schema. Creating a star schema in Power BI is the best practice to improve performance and more importantly, to ensure accurate results! https://www.youtube.com/watch?v=1Kilya6aUQw
  3. Use a small set up sample data when developing. When building your measures and calculated columns always use a small amount of sample data so that it will be easier to confirm that you are getting the right numbers.
  4. Store all your intermediate calculations in VARs when you’re writing measures. You can return these intermediate VARs instead of your final result  to check on your steps along the way.




Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.