cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MatjoCol
Frequent Visitor

SQL Type UniqueIdentifier converted to text behaves differently in M vs DAX

I have two databases with a column Id in them. In one of the databases the Id column has type UniqueIdentifier. In the other database the type is varchar(50) as it contains ids in different formats. When you look at the Ids in SQL Management Studio they look like this: 

MatjoCol_0-1635845317720.png

When you import data into Power BI they look like this. 

MatjoCol_1-1635845545780.png

Power BI has converted the UniqueIdentifier to text and made it lower case as a GUID should be formatted according to RFC4122. If you merge the data in query mode it looks great. 

MatjoCol_2-1635845716195.png

However when you close and apply and look at the data it looks like this: 

MatjoCol_3-1635846200331.png

For some reason the Id column that was UniqueIdentifier originally is now represented with upper case and the merge fails as Source2 id is nvarchar that retains its capitalization. 

In order to get this merge to work you need to perform an additional step of lowercase in query editor. 

There seems to be some sort of glitch with how the data is represented and this could be quite difficult for a user to understand why it behaves like this. 

 

If you create a connection using model you can join these tables without any problem. 

 

2 REPLIES 2
PhilipTreacy
Super User
Super User

Hi @MatjoCol 

 

I think what you are seeing is a result of the way DAX stores strings.  There's a good article about it here

 

Letter case-sensitivity in DAX, Power BI and Analysis Services - SQLBI

 

Basically DAX is case-insensitive and when it's storing strings, if it comes across anothjer string that is identical to one that it has already encountered, the second string is stored exactly the same as the first string.

 

So if it finds ABCD in your data first, then finds abcd, the 2nd string, abcd, actualy gets stored as ABCD.

 

So I suspect that DAX is finding your upper case ID first and storing all occurrences of it in upper case.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


@PhilipTreacy 
Thank you for your reply! 
I read the article but I cannot see how it applies here. 
Create the following example: 
Query1 (connect to random database)

SELECT CAST('0011661B-2AFC-4308-9550-1BC80576EDA1' as UniqueIdentifier) as Id, '2021-11-01' as Date1

 

Query2 (connect to random database)

SELECT CAST('0011661b-2afc-4308-9550-1bc80576eda1' as varchar(50)) as Id2, '2021-11-01' as Date2

 

Import these, merge query1 with query2 on id = id2. This will look good in query editor. But you will get NULL on the join after you have applied it. 

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!