Forum Discussion

YevgenyM's avatar
YevgenyM
Icon for Advocate IV rankAdvocate IV
2 months ago

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:

  1. 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).

  2. 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

  • 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?

  • 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 

     

    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_table
    

     

    This 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's avatar
    v-abhinavmu
    Icon for Community Support rankCommunity 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's avatar
    v-abhinavmu
    Icon for Community Support rankCommunity 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