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
talsed
Frequent Visitor

Lookup between virtual tables without relationship

Hi guys,

I am quite new to DAX magic and been practicing a lot in the last few months, but still I can't fully understand the concept of lookup values based on columns from "virtual tables", even though I've read the articles about it, and also about the TREATAS function that probably should help here. No matter which method i've used in my code to add the column of lookup value from one table to another, I'm getting the same message of "table variable "xxx" cannot be used in this concept, because a base table is expected" 😕

 

Anyway, my example is very simple: 

 

 DEFINE
    VAR _size =
        ADDCOLUMNS (

          SUMMARIZECOLUMNS ( 'person'[person id] ), 

          "total", 'measures'[total]

         )
    VAR _tbl =
        ADDCOLUMNS (
            SUMMARIZECOLUMNS ( 'person'[person id], 'mgr'[mgr id] ),
            "lookup", LOOKUPVALUE ( '_size'[total], '_size'[person id], '_tbl'[mgr id], 0 )
        )

EVALUATE
_tbl

 

 

definitions:

'person' and 'mgr' are actual physical tables, [total] is a meassure as part of the model.

so the idea is to add a new column to _tbl1 called "lookup" that will bring the [total] for each [mgr id] matching [mgr id] to [person id].

so as mentioned the error i get is about the fact that those tables are not physical ones in my model, but a virtual temp tables that i'm creating in thie query.

 

so what's the method that can be used to do a lookup between non-related virtual table variables? 

thanks!

2 REPLIES 2
johnt75
Super User
Super User

I think you can do the whole thing in 1 step without needing the first table

DEFINE
    VAR _tbl =
        ADDCOLUMNS (
            SUMMARIZE ( 'person', 'person'[person id], 'mgr'[mgr id] ),
            "mgr size",
                VAR CurrentManager = 'mgr'[mgr id]
                VAR Result =
                    CALCULATE (
                        [total],
                        REMOVEFILTERS ( 'mgr'[mgr id] ),
                        TREATAS ( { CurrentManager }, 'person'[person id] )
                    )
                RETURN
                    Result
        )

EVALUATE
_tbl

thanks but it didn't help. 

also it's getting error as there are 2 different tables of 'person' and 'mgr' in SUMMARIZE function. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.