Forum Discussion
Power BI Composite Keys: Performance vs. Maintenance tradeoffs in a Lakehouse architecture
Hi All,
Since Power BI doesn't natively support relationships using multiple columns, creating a single-column surrogate/composite key is a standard requirement.
However, when working within a Lakehouse architecture (e.g., Microsoft Fabric / Delta tables), the choice of how and where to generate these keys introduces significant tradeoffs between processing performance and code maintainability.
I would love to hear how the community handles this. Specifically:
Which approach do you use to generate the keys?
Simple string concatenation: Col1 & "-" & Col2 (High storage/memory impact in VertiPaq, but easy to read).
Hashing functions: HASH() / MD5() / SHA256() (Fixed width, fast comparison, but risk of collisions or wider binary types).
Where and how do you maintain this logic?
Upstream in the Lakehouse Gold/Silver layer using Spark SQL / PySpark?
Downstream in Power Query / M?
Via DAX calculated columns (generally avoided for performance, but used for quick fixes)?
How do you strike the best balance between backend optimization and clean, maintainable code? Looking forward to your insights and real-world architectures!
Thanks in advance!
8 Replies
- YevgenyM
Advocate IV
Hi All,
Since Power BI does not natively support relationships using multiple columns,
How do you create single field generenrated keys ? Specifically if you work with Lakehouse?
Which solution do you use?
How do you maintain it in the code?- TomMartens
Super User
Hey YevgenyM,
see my anserwer here: https://community.fabric.microsoft.com/t5/Desktop/Power-BI-Composite-Keys-Performance-vs-Maintenance-tradeoffs-in/m-p/5287880#M1471868
Regards,
Tom
- TomMartens
Super User
Hey YevgenyM ,
I/we lean toward this:
No matter of the data architectecture, meaning if there is a lakehouse or not we are replacing business keys witha surrogate key, meaning integer values. We do not do that if the resulting semantic model is small, less than 1M rows in the largest table(s),
We are doing this using Power Query, if we are using Dataflows (Gen 1or Gen 2) we are making use of linked entities as we are on dedicated capacities. We load source data (..._raw), we transform the raw data, this includes creating the surrogate key (... transform), and finally we build the tables that are consumed by applications further downstream, e.g., semantic models (..._model).
As soon a lakehouse gets involved we are shifting moving the layered dataflows to the metal layers of the lakehouse. We have a tendency to replace dataflows with notebooks, but this is also because we have more data engineers that are familiar with Python than with SQL.
Hopefully this helps to tackle your challenge.
Regards,
Tom- YevgenyM
Advocate IV
I don't understand how you create the surrogate keys using integer values.
Which functions do you use?
Dataflow is not spark - it is not distributed MPP concept AFAIK- TomMartens
Super User
Hey,
I think this will provide an idea of how to create a surrogate key in Power Query / Dataflows: https://exceleratorbi.com.au/replace-guids-with-a-surrogate-key-for-better-performance/
And there are tons of examples of how to create a surrogate keys in Spark
Regards,
Tom
- tharunkumarRTK
Super User
I would recommend
Create a numeric surrogate key inside a fabric notebook in silver layer of your medallion architecture. You can use Spark SQL functions to do so.
Please find the samepl code which would take first 15 characters from the column and conversion it into a numeric key of 16 digits.
SELECT CAST(CONV(SUBSTRING(MD5(business_key), 1, 15), 16, 10) AS BIGINT) AS numeric_key FROM my_tableThis way you should be able to use them in Power BI to relate two tables. Since numberic keys would not a large memory footprint it will not cause issues in power bi.
Connect on LinkedIn
You can read my blogs here: https://www.techietips.co.in/
Did I answer your question? Mark my post as a solution! If I helped you, click on the Thumbs Up to give Kudos.
Proud to be a Super User!
- v-abhinavmu
Community Support
Hi YevgenyM,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.
Thank you. - v-abhinavmu
Community Support
Hi YevgenyM,
May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.
Thank you