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 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:
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!
Hi @Chris2016 for "cleaning" please use Power Query.
Proud to be a Super User!
Thanks for the reply, I have to do it in DAX.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |