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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ells69
Helper I
Helper I

Pattern for getting a value from another fact table based on value from current table

I have two trimmed down fact tables and two dimension tables. The dimesnion tables filter both fact tables.

For my inventory (fact) table I want to retrieve the order id from the orders table. In the report  there is a table showing inventory details at the level of [Key_Product_businessUnit].

My Measure is 
OrderID = 
VAR VAR_Key_Product_businessUnit = SELECTEDVALUE('inventory'[Key_Product_businessUnit])
VAR VAR_Result = 
CALCULATE(
                    MAX('Orders'[OrderID]),
                    'Orders'[Key_Product_businessUnit] = VAR_Key_Product_businessUnit
)
RETURN
VAR_Result


Is this the best pattern to use. It seems to be really slow? There is only one row (or so the business users tell me) in Orders for each row in inventory.

JUst does not seem efficient.

Thanks

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @ells69 
You may try with TREATAS. It is not usually super fast but it could improve the performance in some scenarios.

OrderID =
IF (
    HASONEVALUE ( 'inventory'[Key_Product_businessUnit] ),
    CALCULATE (
        MAX ( 'Orders'[OrderID] ),
        TREATAS (
            VALUES ( 'inventory'[Key_Product_businessUnit] ),
            'Orders'[Key_Product_businessUnit]
        )
    )
)

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @ells69 
You may try with TREATAS. It is not usually super fast but it could improve the performance in some scenarios.

OrderID =
IF (
    HASONEVALUE ( 'inventory'[Key_Product_businessUnit] ),
    CALCULATE (
        MAX ( 'Orders'[OrderID] ),
        TREATAS (
            VALUES ( 'inventory'[Key_Product_businessUnit] ),
            'Orders'[Key_Product_businessUnit]
        )
    )
)
johnt75
Super User
Super User

If there is only 1 order then you could use LOOKUPVALUE, e.g.

OrderID Measure =
VAR VAR_Key_Product_businessUnit =
    SELECTEDVALUE ( 'inventory'[Key_Product_businessUnit] )
VAR VAR_Result =
    LOOKUPVALUE (
        'Orders'[OrderID],
        'Orders'[Key_Product_businessUnit], VAR_Key_Product_businessUnit
    )
RETURN
    VAR_Result

You could also do it as a calculated column like

OrderID Column =
LOOKUPVALUE (
    'Orders'[OrderID],
    'Orders'[Key_Product_businessUnit], 'inventory'[Key_Product_businessUnit]
)

You would probably get better performance doing it as a column.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.