Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Dax query to emulate power bi dashboard report table results. Hierarchical model of parent (pml) < child (mbm) < child (mbpl).
DaxStudio screenshot below. "VAR pml_id" gives same error as shown. " = 'pml'.[Id] " link is a table so why the same error?
Code used above
/* model pml < mbm < mbpl */
DEFINE
TABLE pml = -- pml.id = 3921
FILTER (
'Project Master List',
'Project Master List'[DIR] = "CO" &&
'Project Master List'[Initiative Name] = "Fleet Business Transformation"
)
VAR pml_id =
ROW (
"Id", MAX ( 'pml'[Id] )
)
TABLE mbm =
FILTER (
'Measure Benefit Master',
'Measure Benefit Master'[DIR] = "CO" &&
--'Measure Benefit Master'[PM IDId] = pml_id
'Measure Benefit Master'[PM IDId] = 'pml'[Id]
)
EVALUATE
VAR dummy = 'DirectorateAbbreviation'
RETURN
--dummy
--pml
--pml_id
mbm
Solved! Go to Solution.
Yes, you've hit the nail on the head: "query tables" created with DEFINE TABLE cannot reference each other!
But variables can 🙂
I'm not sure if your query has evolved since your last post, but I would possibly suggest something like:
EVALUATE
VAR pml_id =
-- pml.id = 3921
CALCULATE (
MAX ( 'Project Master List'[Id] ),
'Project Master List'[DIR] = "CO",
'Project Master List'[Initiative Name] = "Fleet Business Transformation"
)
VAR mbm =
CALCULATETABLE (
'Measure Benefit Master',
'Measure Benefit Master'[DIR] = "CO",
'Measure Benefit Master'[PM IDId] = pml_id
)
RETURN
mbm
Posting the final working solution(s) for the parent < child model
Run with only mbm changed as per suggestion from Owen
Run with suggested changes to both var queries
Error pointing to need for table usage, there are 4 rows to be connected.
Try as table declarations and same error
> one can not have nested references Introducing DEFINE TABLE in DAX queries
> now I understand the preference for variable @OwenAuger
reducing the query further Defining variables in DAX queries
Yes, you've hit the nail on the head: "query tables" created with DEFINE TABLE cannot reference each other!
But variables can 🙂
I'm not sure if your query has evolved since your last post, but I would possibly suggest something like:
EVALUATE
VAR pml_id =
-- pml.id = 3921
CALCULATE (
MAX ( 'Project Master List'[Id] ),
'Project Master List'[DIR] = "CO",
'Project Master List'[Initiative Name] = "Fleet Business Transformation"
)
VAR mbm =
CALCULATETABLE (
'Measure Benefit Master',
'Measure Benefit Master'[DIR] = "CO",
'Measure Benefit Master'[PM IDId] = pml_id
)
RETURN
mbm
I would suggest doing away with the DEFINE TABLE statements, and just use DEFINE VAR.
I couldn't see anything in the query that relied on query tables, so table variables should be sufficient.
Using this method, pml_id can be defined using MAXX.
Does the below work?
/* model pml < mbm < mbpl */
DEFINE
VAR pml =
-- pml.id = 3921
FILTER (
'Project Master List',
'Project Master List'[DIR] = "CO"
&& 'Project Master List'[Initiative Name] = "Fleet Business Transformation"
)
VAR pml_id =
MAXX ( pml, 'Product'[Id] )
VAR mbm =
FILTER (
'Measure Benefit Master',
'Measure Benefit Master'[DIR] = "CO"
&& 'Measure Benefit Master'[PM IDId] = pml_id
)
EVALUATE
VAR dummy = 'DirectorateAbbreviation'
RETURN --dummy
--pml
--pml_id
mbm
Regards
@OwenAuger Thank you. Lots of reading via searching 'dax calculatetable vs filter return value'.
FILTER vs CALCULATETABLE was a good discussion around the difference. 'CALCULATETABLE triggers context transition whereas FILTER does not. Andy by itself, FILTER creates a row context whereas CALCULATETABLE does not.' Yet when you look at their defininitions both return tables :}
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
11 | |
11 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |