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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Chris2016
Resolver I
Resolver I

Clean up column of unwanted strings using DAX

Hello,

I have to do a clean up in a very messy column where I have to remove various strings in front or after the text I want to keep.

I have a table like this:

User
123gb233v-dan
46535jdfsfa8v-smit
62773j73662mig_ne_nahd
7266gdv715453ke_haf_te
abb_hdg_hsg.main
abb_hdg_n.abou.hagd
a-ghgd_company
a-has_my_company
cnx_suz-gi
cvg_bhhs_ad
johnb
maxv_2mk

 

So far, I removed text before a "v-", and kept text that is before a "_my_company" or "_company" string:

_Cleaned User =
var _identify = FIND("v-", 'Table'[User],, blank())
var _length = FIND("v-", 'Table'[User],, LEN('Table'[User]))
var firstclean = SWITCH(TRUE(), NOT(ISBLANK(_identify)),RIGHT('Table'[User], LEN('Table'[User])-_length+1), 'Table'[User])
var _identify2 = FIND("_my_company", firstclean,, blank())
var _length2 = FIND("_my_company", firstclean,, LEN(firstclean))
var secondclean = IF(NOT(ISBLANK(_identify2)), LEFT(firstclean, _length2-1), firstclean)
var _identify3 = FIND("_company", secondclean,, blank())
var _length3 = FIND("_company", secondclean,, LEN(secondclean))
var thirdclean = SWITCH(TRUE(), NOT(ISBLANK(_identify3)),LEFT(secondclean, _length3-1), secondclean)
return thirdclean

Here is the result:

 

Chris2016_0-1692283954973.png
What I need next is a way to remove any string that is longer than 10 characters that contains number values (e.g. from "62773j73662mig_ne_nahd" I want to keep "mig_ne_nahd"). In this condition, LEN('Table'[User])>10 should be included because I have some values that contain numbers, which I want to keep as such (e.g. "maxv_2mk").

Is there any way this can be done?
Also, if you have any suggestions on improving the formula, I'd appreciate the insights.

Thanks!

 

2 REPLIES 2
some_bih
Super User
Super User

Hi @Chris2016 for "cleaning" please use Power Query.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Thanks for the reply, I have to do it in DAX.

Helpful resources

Announcements
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.