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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JorgenMaass
New Member

Remove reoccurring text elements in column (text)

I have a table with a column "Indata" (type text). Each row consist of a set of comma separated "textelements".
For some of the rows the same textelement occurs more than once. 
I would like to get help to find the DAX expression to filter out the copies.


JorgenMaass_0-1632251532868.png

1 ACCEPTED SOLUTION

@JorgenMaass Correct, that was the intention!! Here is the fully script:

Result Column =
  VAR __Text = SUBSTITUTE([Indata],", ","|")
  VAR __Count = PATHLENGTH(__Text)
  VAR __Table = 
    DISTINCT(
      SELECTCOLUMNS(
        ADDCOLUMNS(
          GENERATESERIES(1,__Count,1),
          "__Word",PATHITEM(__Text,[Value])
        ),
        "__Word",[__Word]
      )
    )
RETURN
  CONCATENATEX(__Table,[__Word],", ")

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

6 REPLIES 6
Greg_Deckler
Super User
Super User

@JorgenMaass Here's one way:

Result Column =
  VAR __Text = SUBSTITUTE([Indata],", ","|")
  VAR __Count = PATHLENGTH(__Text)
  VAR __Table = 
    DISTINCT(
      SELECTCOLUMNS(
        ADDCOLUMNS(
          GENERATE(1,__Count,1),
          "__Word",PATHITEM(__Table,[Value])
        ),
        "__Word",[__Word]
      )
    )
RETURN
  CONCATENATEX(__Table,[__Word],", ")

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler thanks for a quick reply!
But I dont get it to work:

 

JorgenMaass_0-1632256312711.png

 

@JorgenMaass Whoops, used the wrong variable. Can't believe that was the only issue, I winged it.

Result Column =
  VAR __Text = SUBSTITUTE([Indata],", ","|")
  VAR __Count = PATHLENGTH(__Text)
  VAR __Table = 
    DISTINCT(
      SELECTCOLUMNS(
        ADDCOLUMNS(
          GENERATE(1,__Count,1),
          "__Word",PATHITEM(__Text,[Value])
        ),
        "__Word",[__Word]
      )
    )
RETURN
  CONCATENATEX(__Table,[__Word],", ")

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thx again. Still dont get it to work.
2 errors: 
* [Value] is an unknown variable
* GENERATE(1,     Parameter is incorrent type

Best regards

JorgenMaass_0-1632257389969.png

 

@Greg_Deckler it works if I use GENERATESERIES() instead of GENERATE.
 

@JorgenMaass Correct, that was the intention!! Here is the fully script:

Result Column =
  VAR __Text = SUBSTITUTE([Indata],", ","|")
  VAR __Count = PATHLENGTH(__Text)
  VAR __Table = 
    DISTINCT(
      SELECTCOLUMNS(
        ADDCOLUMNS(
          GENERATESERIES(1,__Count,1),
          "__Word",PATHITEM(__Text,[Value])
        ),
        "__Word",[__Word]
      )
    )
RETURN
  CONCATENATEX(__Table,[__Word],", ")

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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