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
soldstatic
Resolver I
Resolver I

Hasbytes as Primary Key

Hello,

 

We're creating a data model in sql server that combines data from multiple sources in our data lake. We're trying to build it with the future in mind as we will likely turn it into an ETL type process as well. For the moment, it is basically a series of views that we've defined. 

 

In doing this, we have multiple columns within each view that when considered together act as a 'primary key' for that view. Each of the three main views have their own key, and are tied to each by this key (group of columns).

 

I defined this key in the view by using hashbytes, as in the snippet below. My problem is that PowerBI loads the hashbyte column as binary within query editor, but outside of query editor these columns don't seem to exist. My goal was to be able to create a simple relationship within powerBI between the three main views utilizing this column for the 'joins' between them, but I can't seem to define that relationship from the modelling tab within PBI desktop because it doesn't show that column at all. If I change the type in query editor to change it to text instead of binary, I receive an error when applying the changes that this type of transformation cannot be used with direct query. 

 

Please help!

Andy

 

ALTER view [CustomerView] as
	select HASHBYTES('SHA2_256',
			CONCAT(SourceSystemID,'␟'
				,SourceSystemVersion,'␟'
				,ETLVersion,'␟'
				,ETLDatetime,'␟'
				,RecordVersion,'␟'
				,CustID,'␟'
				)) as CustomerKey
				,* from Customer
1 ACCEPTED SOLUTION

I was able to switch to the CHECKSUM() function within sql server. I think this will work, but I'm waiting on some indices from our DBA group before I can actually run my verifications. However, this did come into power BI as a number so I was able to use this as the key linking the tables together. My performance is terrible w/o the indices, but I think the CHECKSUM has done what I needed it to do.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hashbytes apparently works in PowerQuery now.  I'm using this: 

 

convert(nvarchar(50),hashbytes('MD4' ,BR.projecttitle),2)

 

 

v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @soldstatic

 

Yes, I'm afraid that we cannot convert the data type when in direct query mode.

 

We may try another way, you could have a reference of this similar thread which has been solved.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I was able to switch to the CHECKSUM() function within sql server. I think this will work, but I'm waiting on some indices from our DBA group before I can actually run my verifications. However, this did come into power BI as a number so I was able to use this as the key linking the tables together. My performance is terrible w/o the indices, but I think the CHECKSUM has done what I needed it to do.

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.