Really your case has and other ways of solution in SQL
I used
Code:
Select Sum(amt) From (
Select fact.key, amt From fact Inner Join onedim on (fact.onekey = onedim.onekey)
Union
Select fact.key, amt From fact Inner Join twodim on (fact.twokey = twodim.twokey)
) tOr
Inner Join fast tmain On (tmain.key = tOr.fact.key)
Inner Join otherDim on (tmain.otherkey = otherDim.otherkey)
Group By otherDim.otherkey;
We can use Full Outer Join too
Code:
Select Sum(amt) From (
Select key, amt From (
(Select fact.key, amt From fact Inner Join onedim on (fact.onekey = onedim.onekey)) tone
Full Outer Join
(Select fact.key, amt From fact Inner Join twodim on (fact.twokey = twodim.twokey)) ttwo
On (tone.key = ttwo.key)
) tOr
Inner Join fast tmain On (tmain.key = tOr.fact.key)
Inner Join otherDim on (tmain.otherkey = otherDim.otherkey)
Group By otherDim.otherkey;
In Excel 2013 or 2010 you are able to use full outer DAX equivalent
Code:
= Calculate(Sum(fact[amt]), onedim[onekey] = 1; twodim[twokey] <> 2)
+ Calculate(Sum(fact[amt]), onedim[onekey] = 1; twodim[twokey] = 2)
+ Calculate(Sum(fact[amt]), onedim[onekey] <> 1; twodim[twokey] = 2)
Is it longer than SQL? Yes, it is. Is it difficult? I am not sure.
Has DAX weirdnesses? As for me an answer is yes.
Let see on my measure Union function work as SQL Union (but it is Union All by defintion). Ok, let rewrite it in other style.
Code:
=Var factKeyByOneDim = CALCULATETABLE(VALUES('fact'[key]); 'oneDim'[oneDim] = 1)
Var factKeyByTwoDim =CALCULATETABLE(VALUES('fact'[key]); 'twoDim'[twoDim] = 2)
Var factKeyByOr = UNION(factKeyByTwoDim; factKeyByOneDim)
Var factOrData = NATURALINNERJOIN('fact'; factKeyByOr)
Return SUMX(factOrData; 'fact'[value])
In this case DAX Union works as Union All. I do not know why. Maybe it is special behavior inside Calculate or CalculateTable.
I do not understand why in SUMX function in my example I must write 'fact'[value], but not factOrData[value].
I do not understand why it works
Code:
Calculate(Count(oneDim[onekey]); fact)[
But that does not at all.
Code:
Calculate(DictinctCount(oneDim[onekey]); Values(fact[onekey]))
In Microsoft Excel 2013 Building Data Model with PowerPivot authors of Definitive Guide wrote it so difficult for explanation
Regards,