问题
A user trying to check the Sales Amount per Salesperson. Sample data:
Salesperson Sales Amount
001 1000
002 500
003 750
Grand Total: 2250
It looks fine, but we have the following hierarchy Company > Class > Group > Subgroup
in the cube and if a user tries to use this hierarchy in filters - Grand Total fails (if any attribute is unchecked in this hierarchy). Sample:
Salesperson Sales Amount
001 1000
002 500
003 750
Grand Total: 350
I've noticed the same problem before when we tried to filter Date attribute, if not every day of the month was selected it shown wrong Grand Total too.
Have you an idea why it happens and how to fix it?
Sales Amount is physical measure (not calculated measure), it is selected from SQL view (the same happens with every fact).
I've asked the same question here, but nobody could answer it.
I've tried to delete all MDX calculations (scopes), but still Grand Total was incorrect.
EDIT
I've noticed that the problem occurs when filtering like that:
1 element selected from the first level of the hierarchy, 1 element from 2nd level and 1 element from the 3rd level of hierarchy as in the image above.
If the 3rd level isn't filtered it shows good Grand Total.
EDIT 2
I've tried to trace on SSAS, it returns exactly the same output as in Excel. It generated the following MDX when using Salesperson dimension on the rows:
SELECT NON EMPTY { [Measures].[Sales Amount] } ON COLUMNS,
NON EMPTY { ([Salesperson].[Salesperson].[Salesperson].ALLMEMBERS ) }
DIMENSION PROPERTIES MEMBER_CAPTION,
MEMBER_UNIQUE_NAME ON ROWS FROM (
SELECT ( { [Item].[Class - Group - Subgroup].[Class].&[XXX]&[1.],
[Item].[Class - Group - Subgroup].[Group].&[XXX]&[2.]&[2.2.],
[Item].[Class - Group - Subgroup].[Subgroup].&[XXX]&[2.]&[2.3.]&[2.3.1.] }
) ON COLUMNS FROM ( SELECT ( { [Company].[Company].&[XXX] } ) ON COLUMNS
FROM [Sales]))
WHERE ( [Company].[Company].&[XXX], [Item].[Class - Group - Subgroup].CurrentMember ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
This MDX generated without Salesperson dimension:
SELECT NON EMPTY { [Measures].[Sales Amount] } ON COLUMNS
FROM ( SELECT ( { [Item].[Class - Group - Subgroup].[Class].&[XXX]&[1.],
[Item].[Class - Group - Subgroup].[Group].&[XXX]&[2.]&[2.2.],
[Item].[Class - Group - Subgroup].[Subgroup].&[XXX]&[2.]&[2.3.]&[2.3.1.] } ) ON COLUMNS
FROM ( SELECT ( { [Company].[Company].&[XXX] } ) ON COLUMNS
FROM [Sales])) WHERE ( [Company].[Company].&[XXX], [Item].[Class - Group - Subgroup].CurrentMember ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
I've noticed even if I'm not using any dimension on the rows (in samples above I've used Salesperson dimension) it shows wrong Grand Total.
For example it shows:
Sales Amount
350
And when using Salesperson dimension on the rows:
Salesperson Sales Amount
001 1000
002 500
003 750
Grand Total: 350
回答1:
I suspect you have an unusual Aggregate Function set on Sales Amount, e.g. ByAccount, AverageOfChildren. It should probably use Sum. Check the properties of the Sales Amount measure.
https://docs.microsoft.com/en-us/sql/analysis-services/multidimensional-models/use-aggregate-functions?view=sql-server-2017
回答2:
I would like to take another angle to this one and suggest that it is not SQL/SSAS that is the problem here but Excel. In a pivot table with subtotals and grand totals the totals are not calculated by the cube but the client-side application. I have experienced this a few times and found this to be a known issue with Excel. The solution typically involves creating a new calculated field in Excel to provide the grand total. This is frustrating especially if Excel is the go-to client application for other users accessing the cube. If it is any consolation, I've also experienced this a time or two in other tools such as Tableau but for slightly different reasons with different solutions.
Here is a link to a Microsoft KB acknowledging the problem. Affects versions 2003-2019!!!
https://support.microsoft.com/en-us/help/211470/calculated-field-returns-incorrect-grand-total-in-excel
来源:https://stackoverflow.com/questions/55760416/in-olap-cube-wrong-grand-total-when-attribute-is-filtered