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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
eddydm
Advocate II
Advocate II

Privacy - Hashing of keys

Hey,

 

 

In a powerbi-file i have some related tables. Some of the relations uses a key which contains specific personal-related-information, which may not be visable to 'the whole world' (privacy rules.)

I want to hash this key and use this hashed values in the relations.

 

Some questions:

* is the hashing of the key possible?

* Can some give me an example how to calculate this hashing. I like to use dax-formulas, not the r-scripting.

 

 

Kind regards

 

 

Eddy

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @eddydm,

 

I haven't find any function to directly convert the string to hash string (dax and power query not contain).

 

For your requirement, you can try to use below methods if it works on your side:

 

1. T-sql.

 

Use a static string to instead of the privacy information or use hasbytes to transform.

 

Capture.PNG

 

2. R script.

Write a r script which use to convert the string, then run it in query editor.

 

3. Web.Content.

Add a custom step which use to call a transform string api/webservice.

 

Reference links:

HASHBYTES (Transact-SQL)

Using R in Query Editor

Web.Contents

Power Query Functions–Some Scenarios

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
akristiansson
Advocate I
Advocate I

Old thread, but I had a similar need and I've found a pure Power Query/M solution to this...

 

M can compress binary data as gzip, the gzip footer contains a 32-bit CRC checksum which we can access and use as a uniformly sized hash:

 

CalculateHash = (x as text) as number => BinaryFormat.UnsignedInteger32(
    Binary.FromList(
        List.FirstN(
            List.LastN(
                Binary.ToList(
                    Binary.Compress(Text.ToBinary(x, BinaryEncoding.Base64), Compression.GZip)
                ),
            8), 
        4)
    )
)

The footer is 8 bytes, the first 4 of which contains the checksum. We convert the gzip binary to a list in order to extract the relevant bytes and in turn convert this to a non-negative number. Alternatively, you could use the hex value for a text hash:

 

CalculateHash = (x as text) as text => Binary.ToText(
    Binary.FromList(
        List.FirstN(
            List.LastN(
                Binary.ToList(
                    Binary.Compress(Text.ToBinary(x, BinaryEncoding.Base64), Compression.GZip)
                ),
            8), 
        4)
     ),
BinaryEncoding.Hex)

 

This is a brilliant answer

Anonymous
Not applicable

I need user Hash md5. Can I do it on Power Bi witch M language.

The post by akristiansson is highly useful but it might be easier for typical users if Perfect Hash Functions were implemented in Power BI [1] out-of-the-box so the users would not have to resort to Power Query M:
https://crypto.stackexchange.com/questions/8765/is-there-a-hash-function-which-has-no-collisions/212...

From a personal standpoint, I should be able to figure out how to apply akristiansson's method; unfortunately, I'm not sure if the "average" Power BI users are going to want to do that everytime they import sensitive Row Ids.  When users import data into Power BI, they should be given an option to supply a key that will automatically Perfectly Hash the senstive colums (without collisions) before they are loaded into Power BI.  The users would then be responsible for safeguarding that key in case they ever need to apply the Perfect Hash for future imports of related data.

[1] - Also, assuming the datasource is an onsite MS SQL Server, it's posible that MS SQL Server could be modified to apply the Perfect Hash to the senstive colums before they are loaded into Power BI and/or read by DirectQuery.

 

v-shex-msft
Community Support
Community Support

Hi @eddydm,

 

I haven't find any function to directly convert the string to hash string (dax and power query not contain).

 

For your requirement, you can try to use below methods if it works on your side:

 

1. T-sql.

 

Use a static string to instead of the privacy information or use hasbytes to transform.

 

Capture.PNG

 

2. R script.

Write a r script which use to convert the string, then run it in query editor.

 

3. Web.Content.

Add a custom step which use to call a transform string api/webservice.

 

Reference links:

HASHBYTES (Transact-SQL)

Using R in Query Editor

Web.Contents

Power Query Functions–Some Scenarios

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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