Forum Discussion
REPLACE Function Returning Unexpected Results
- 4 years ago
tamerj1 so, becasue until someone else will say otherwise, you found a bug 🙂
In the mean time, I just jumped over it and solved it in another way (I'm adding the DAX Query):EVALUATE VAR _CurrentTitle = SELECTCOLUMNS ( FILTER ('Table', 'Table'[Title] = "set field title case" ), "@Title", [Title] ) VAR _Length = LEN ( _CurrentTitle ) VAR T1 = GENERATESERIES ( 1, _Length, 1 ) VAR T2 = ADDCOLUMNS ( T1, "@Title", _CurrentTitle, "@SapceLocation", FIND ( " ", _CurrentTitle, [Value], BLANK ( ) ) ) VAR T3 = FILTER ( T2, [Value] = 1 || [@SapceLocation] = [Value] ) VAR T4 = ADDCOLUMNS ( T3, "@LetterLocation", IF ( [Value] = 1, 1, [Value] + 1 ) ) VAR T5 = ADDCOLUMNS ( T4, "@FirstLetter", MID ( [@Title], [@LetterLocation], 1 ) ) VAR T6 = ADDCOLUMNS ( T5, "@CapitalLetter", UPPER ( [@FirstLetter] & "" ) ) VAR T7 = ADDCOLUMNS( T6, "@Extracted Letter", MID ( [@Title], [@LetterLocation], COALESCE( MINX( FILTER( T6, [@LetterLocation] > EARLIER([@LetterLocation]) ), VALUE([@LetterLocation]) ), _Length * 3 ) - [@LetterLocation] - 1 ) ) VAR T8 = ADDCOLUMNS ( T7, "@Extracted Letter Title Case", REPLACE ( [@Extracted Letter], 1, 1, [@CapitalLetter] ) ) VAR Result = { CONCATENATEX ( T8, [@Extracted Letter Title Case], " ", [@LetterLocation], ASC ) } RETURN Result
SpartaBI
This is amazing! splitting the sentence into words bypassed the the "bug" 🙂 Great job my friend!!!
As small problem when having a single word. The extraction seems to miss the last letter. I guess you can solve that. Otherwise it works perfect!
On the other hand I hope DAX experts can confirm if this is really a bug or this is just a DAX behaviour which we could not understand. I Don't want to be rude but AlbertoFerrari and marcorusso who's more competent than you guys to answer this question.
tamerj1 my pleasure my friend 🙂 I was very happy I had a chance to help you.
I really appreciate your skills.
Regarding the one word, so basically it's just the scenario when the coalesce kicks in, so just need to have there a large enough number. I'm editing the code now in the original message and changing it to be _Lentgh * 3
- tamerj14 years agoCommunity Champion
I'm here just to learn. It is amazinghow much a person can learn just trying to answer questions and reading other people answers. I heard about DAX last August and strted baby steps with Power Pivot two months later. My first experience with Power Bi was about 3 months ago.
Thank you again you are really amazing! And there slot to be learned from this small piece of code youve added.
FYI I have no business with data analysis whatsoever. I'm just a mechanical engineer working at construction sites but I found DAX interesting.- SpartaBI4 years agoCommunity Champion
tamerj1 well, I can tell you for sure, that you have a natural talent for DAX and I'm pretty sure you can be a top notch data analyts and/or data developer whenever you will want to :).
Have you read the definitive guide to dax? Basically just read that and/or take their course and watch all their videos and you will be one of the best in the world for sure.- tamerj14 years agoCommunity Champion
SpartaBI ❤️
I read every single page and still referring back to it almost everyday. I have a gold fish memory 😅
I watched every single video in SQLBI youtube channel and all the free tutorial in SQLBI website. I think my advantage is that I'm not from IT background and I've never learned before any other programming language. So I guess my mind was not presett based on typical programming languages.