Emile Joubert
05/28/2024, 6:18 PMfct_lines
and dim_returns
) with a foreign key relation and 2 metrics (q1/q2
and fit q1/q2
). when i compute q1/q2
by Attr
i get the expected result:
Attr q1/q2
-----------
attr 0.8
but when i add the second metric the result of the first changes:
Attr q1/q2 fit q1/q2
----------------------
attr 1.0 0.75
• is there a way of defining q1/q2
in a way the prevents this interaction? how do i predict the possibility of this interaction?
• the q1/q2
metric is sensitive to whether `fit q1/q2`` contains a FOR EACH
clause. is this expected?
fct_lines
Key Attr Return_Key Q1 Q2
------------------------------
101 attr 1 1 1
102 attr NA 0 1
103 attr 2 2 2
104 attr 3 1 1
dim_returns
Return_Key Fit
---------------
1 True
2 True
3 False
dim_returns.Return_key <- fct_lines.Return_Key
# fit q1/q2
SELECT (SELECT SUM({fact/q1}) WHERE {label/fit} = "true") / SUM({fact/q2} )
# q1/q2
SELECT SUM({fact/q1}) / SUM({fact/q2})
thanks!Joseph Heun
05/28/2024, 6:27 PMEmile Joubert
05/28/2024, 6:45 PMBY
every available attribute in the data model but none prevent the effect of the second metric on the first. can you suggest a concrete clause to use, in light of the details provided?Joseph Heun
05/28/2024, 7:03 PMEmile Joubert
05/28/2024, 7:12 PMFOR EACH
in one metric would have an effect on another metric. i'm searching for a way to predict the possibility of this happening and to guard against it. can you help me understand why this happens and how to prevent it?Michal Hauzírek
05/28/2024, 7:35 PMq1/q2
metric does not need to join the dim_returns so it calculates on the fact_lines table only, but the moment you add the fit q1/q2
metric, this table has to be joined (to evaluate the value of fit
).
To prevent too heavy queries i.e. scanning the same table multiple times for multiple metrics, there are some optimizations and these assume that all the references are valid. But here the inner join filters out the line 102 and therefore it is not calculated even in the q1/q2
metric.
To fix this, you can add the row with NA return_key value to your dim_returns. Then everything should work as expected.
I am not sure if these requirements for data consistency are stressed enough in the documentation so let me check with the documentation team if we can make them clear there.Emile Joubert
05/28/2024, 8:00 PMMichal Hauzírek
05/28/2024, 8:22 PMEmile Joubert
05/28/2024, 8:53 PMeach and every fct_line has to have exactly one dim_returncan you point me to the reference for this? the example tables and metrics i quoted earlier was distilled from a larger schema where pre-joining won't be feasible. i accept the suggestion you made for making sure outer joins don't occur. i can confirm this prevents the interaction between metrics but i find the need to do that questionable. my understanding from this is that the MAQL semantics depend on the presence of NULLs, and there are no warnings for getting it wrong?