Forum Discussion
Multiply DirectQuery row value with imported table value (DAX)
- 4 years ago
Anonymous I would think the summarize doing its job, what would be the job of related function in a "normal" setting without direct query.
Summarize is doing something like what group by is doing in SQL. Its grouping/aggregating where are many product id (facttable) to the table where is only one productId towards the right weight of that productID.
Thats also why you didnt got the right totals before. You were using the max weight of the entire table instead of the right weight of the filter context.
Anonymous I'm not 100% sure about your mentioned data, but given that one thing did return you the right result for one single product ID, you might try the following.
If your measure is working for one single product ID like you mentioned:
Measure= SUM('fact'[units sold]) * MAX('dim Product'[weight])
Since there is restrictions because of the different import variations try using x-aggregated function to get right totals:
Measure2 = sumx ('Facttable', [Measure])
Applicable88 Thanks for thinking along, I did mention in the opening post that I had tried that. However, SUMX('fact', SUM('fact'[units sold]) * MAX('dim Product'[weight])) gives for totals the units sold (total) multiplied by the maximum of all product weights. I.e. it still doesn't seem to do the calculations at row level. Does something need to be added to the measure to "force" calculations for each row, or are there limitations due to mixed storage model?
- Applicable884 years agoImpactful Individual
Anonymous yes. You should not put the function in, but the Measure. In every measure there there is actually a invisible "calculate" function wrapped around it. But you are calculating everything from the table. You can either try it with two measures like I explained above or you can wrap the calculate function within the "expression" part of SUMX. Like this:
SUMX('fact', calculate (SUM('fact'[units sold]) * MAX('dim Product'[weight])) )
Hope that helps.
- Anonymous4 years agoNot applicable
Applicable88 Thanks, that definitely helps me to understand and points me in a clearer direction.
I've tried just now (with two separate measures), I am getting a very strange error if I bring the final measure in a visual:
OLE DB or ODBC error: Query (8, 2) The column 'PC Group (groups)' specified in the 'SUMMARIZE' function was not found in the input table..
The strange part is that the measure does not contain SUMMARIZE, moreover PC Group is a completely separate dimension (part of the DirectQuery dataset, with only a relationship to the fact table). I understand this seems to go beyond the initial question, but any thoughts on why a measure containing SUMX can generate the above error in a visual?
- Applicable884 years agoImpactful Individual
Hi Anonymous,
I don't know for sure why. But maybe we can try another approach. Since you have a many to 1 relationship lets try step by step to be sure whats happening here.
We now using related function. The related function need to be used from the many side of the table:
Measure : sumx ( 'Facttable','Facttable' [unitssold] * related ( 'dimproduct'[weight])
I now would think you already have the right result for row and as total. Please let me know if it works out for you.
Best.