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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Eastwood
Frequent Visitor

DAX will get false Unicode from character

Hello Community,

 

this is my first time asking a question here! 🙂 

 

I want to find every lower and upper character in a string. To achieve this, I use the following DAX statement:

DEFINE
VAR Repl_Char = FORMAT ("Adma Sandler","STRING")
VAR Mylen = LEN ( Repl_Char )
VAR mytable =
ADDCOLUMNS (
GENERATESERIES ( 1, mylen ), "Original", MID ( Repl_Char, [Value], 1 ))
VAR Result_Uni =
ADDCOLUMNS (
SELECTCOLUMNS (
ADDCOLUMNS ( mytable, "uni_char", UNICODE ( [Original] ) ),
"Number", [Value],
"Original",[Original],
"Unicode", [uni_char]
),
"uppercase_lowercase",
IF (
[Unicode] >= 97
&& [Unicode] <= 122,
"lower",
IF ( [Unicode] >= 65 && [Unicode] <= 90, "upper","non alpha" )
)
)

EVALUATE
Result_Uni

 

If I execute this I will receive the follow:

NumberOriginalUnicodeuppercase_lowercase
1A65upper
2d100lower
3m109lower
4A65upper
5 32non alpha
6S83upper
7A65upper
8n110lower
9d100lower
10l108lower
11e101lower
12r114lower

 

Question:

1. Could someone help to understand why this situation is happend? 

2. It would be really helpful if someone has an idea to solve this. 

 

BTW: I only have the option to use DAX for this challenge. 😉

 

Many thanks

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I'm pretty sure this has to do with case-insensitive column compression as I explain here:

https://community.powerbi.com/t5/Desktop/Single-character-in-Text-field-changing-from-upper-to-lower...

 

While I don't think there's a way to make the [Original] column as you expect, you should be able to fix the other columns by immediately converting to Unicode like this:

DEFINE
VAR Repl_Char = FORMAT ( "Adma Sandler", "STRING" )
VAR Mylen = LEN ( Repl_Char )
VAR mytable =
    ADDCOLUMNS (
        GENERATESERIES ( 1, mylen ),
        "Unicode", UNICODE ( MID ( Repl_Char, [Value], 1 ) )
    )
VAR Result_Uni =
    SELECTCOLUMNS (
        mytable,
        "Number", [Value],
        "Original", UNICHAR ( [Unicode] ),
        "Unicode", [Unicode],
        "uppercase_lowercase",
            IF (
                [Unicode] >= 97 && [Unicode] <= 122,
                "lower",
                IF ( [Unicode] >= 65 && [Unicode] <= 90, "upper", "non alpha" )
            )
    )
EVALUATE
    Result_Uni

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

I'm pretty sure this has to do with case-insensitive column compression as I explain here:

https://community.powerbi.com/t5/Desktop/Single-character-in-Text-field-changing-from-upper-to-lower...

 

While I don't think there's a way to make the [Original] column as you expect, you should be able to fix the other columns by immediately converting to Unicode like this:

DEFINE
VAR Repl_Char = FORMAT ( "Adma Sandler", "STRING" )
VAR Mylen = LEN ( Repl_Char )
VAR mytable =
    ADDCOLUMNS (
        GENERATESERIES ( 1, mylen ),
        "Unicode", UNICODE ( MID ( Repl_Char, [Value], 1 ) )
    )
VAR Result_Uni =
    SELECTCOLUMNS (
        mytable,
        "Number", [Value],
        "Original", UNICHAR ( [Unicode] ),
        "Unicode", [Unicode],
        "uppercase_lowercase",
            IF (
                [Unicode] >= 97 && [Unicode] <= 122,
                "lower",
                IF ( [Unicode] >= 65 && [Unicode] <= 90, "upper", "non alpha" )
            )
    )
EVALUATE
    Result_Uni

Hello @AlexisOlson, many thanks for your explanation! 🙂 I now understand why my approach to identify the characters did not work! 😉 Your solution will save my day! 

amitchandak
Super User
Super User

@Eastwood , Why is there a problem with the other A = 65?

@amitchandak many thx for your reply. The search string "Adma" has the last lower character "a". But the Unicode are referenced to an upper character.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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