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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.