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
Thank you SpartaBI for your response.
I want to get Set Field Title Case
I gues there might be more simple solutions. This for sure will be of my intrest. However, it is now more interesting to me to understand why does this function behave this way! What was the mistake which I was not able to spot?!
tamerj1 ye, I got now to T7 and looking at the bug haha
Indeed just the fact that it doens't work with
REPLACE ( [@Title], [@LetterLocation], 1, [@CapitalLetter] ) )
But works with
REPLACE ( [@Title], [@LetterLocation] + 1, 1, [@CapitalLetter] ) )
looks like some interesting edge case 🙂