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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply

Adding space between texts using Uppercase as an indicator of where the space should be

Hi PowerBI community,

I am keen to understand if it is possible to add space between texts using Uppercase as an indicator of where the space should be:

For instance: "IronmanMarvelSuperhero" to "Ironman Marvel Superhero"

Is this possible? if it is how do we do this in DAX? 

4 REPLIES 4
Oleh116611
Frequent Visitor

Thank you very much @OwenAuger , the solution works perfectly!

OwenAuger
Super User
Super User

Hey again @JuggernautProf 

That's odd - you shouldn't receive those errors if the code has been placed in a calculated column. Then only dependency on the existing model is the reference to 'Text'[Text] at the start.

 

One thing we may need to consider is handling of blank/empty strings.

 

Could you share a link to a sanitised PBIX demonstrating the issue (OneDrive, Google Drive etc), or a screenshot of the Power BI interface showing the table where you're adding the column?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
OwenAuger
Super User
Super User

Hi  @JuggernautProf 

This would probably be best handled further upstream, in data source or Power Query.

However, something like this is possible with DAX.

Here is the code for a calculated column (PBIX attached):

Text With Spaces = 
VAR CurrentText = 'Text'[Text]
VAR SpaceCode = UNICODE ( " " )
VAR UpperMin = UNICODE ( "A" )
VAR UpperMax  = UNICODE ( "Z" )
VAR NumChars = LEN ( CurrentText )
VAR PositionCode =
    SELECTCOLUMNS (
        GENERATESERIES ( 1, NumChars ),
        "@Position", [Value],
        "@Code", UNICODE(MID ( CurrentText, [Value], 1 ))

    )
VAR UpperPositionCode =
    FILTER (
        PositionCode,
        VAR IsUpper =
            [@Code] >= UpperMin
                && [@Code] <= UpperMax
                && [@Position] > 1
        RETURN
            IsUpper
    )
VAR Spaces =
    SELECTCOLUMNS (
        UpperPositionCode,
        "@Position", [@Position] - 0.5,
        "@Code", SpaceCode
    )
VAR NewPositionCode =
    UNION ( PositionCode, Spaces )
VAR Result =
    CONCATENATEX (
        NewPositionCode,
        UNICHAR ( [@Code] ),
        "",
        [@Position]
    )
RETURN 
    Result

OwenAuger_0-1693802094327.png

 

The basic idea is to find the uppercase characters in all positions after the first, then insert a space before each of them and reassemble.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Hey @OwenAuger Thanks. I tried this, however I keep getting an error "DAX comparison pperations do not support comparing values of type Text with values of type integer. Consider using VALUE or FORMAT function to conver one of the values. 

Also in addition to the above, I keep seeing an error with [@code], [@position], "cannot find name [@code]"

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.