Use the hash scalar function to transform any data type as a string of bytes into a signed integer. The result is deterministic so the value is always identical given the same input data.

Use the hash function to:

  • Anonymise personally identifiable information (PII) while preserving joinability.
  • Create reproducible buckets for sampling, sharding, or load-balancing.
  • Build low-cardinality keys for fast aggregation and look-ups.
  • You need a reversible-by-key surrogate or a quick way to distribute rows evenly.

Don’t use hash to generate values for long term usage. hash is generic and the underlying hashing algorithm may change. For long term stability, use the other hash functions with specific algorithm like hash_sha1.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.

Usage

Syntax

hash(source [, salt])

Parameters

NameTypeDescription
valsourceuescalarAny scalar expression except real.
saltint(Optional) Salt that lets you derive a different 64-bit domain while keeping determinism.

Returns

The signed integer hash of source (and salt if supplied).

Use case examples

Hash requesters to see your busiest anonymous users.

Query

['sample-http-logs']
| extend anon_id = hash(id)
| summarize requests = count() by anon_id
| top 5 by requests

Run in Playground

Output

anon_idrequests
-5872831405421830129128
90217536450208761197
-35487961094523785485
642308710592734871374
-91908734572100431769

The query replaces raw IDs with hashed surrogates, counts requests per surrogate, then lists the five most active requesters without exposing PII.