Sometimes it is needed to hash identifiers, as they shouldn’t be readable by users and sometimes the fact that datamodels are faster by joining over integers makes the use of the following function really helpful:
/**
/* @author : philipp@frenzel.net
/* @env: PROD
**/
let
CalculateHash = (x as text) as number =>
try
BinaryFormat.UnsignedInteger32(
Binary.FromList(
List.FirstN(
List.LastN(
Binary.ToList(
Binary.Compress(Text.ToBinary(x, BinaryEncoding.Base64), Compression.GZip)
),
8),
4)
)
)
otherwise
-1
in
CalculateHash
Code-Sprache: PHP (php)
This function makes use of a trick – as m-language doesn’t allow a direct hashing. It generates a unique compressed version from the binary and the checksum will then be used as the result for the hash process.