Hi All,
I'm still reading "Professional Microsoft SQL Server Analysis Services 2008 with MDX" and working through the examples, but I can't finish soon enough. I have a need for an MDX query but I myself am not capable of writing it. I'm looking for the number of customers per country that had at least one order during a particular work week. The report in question will show a variable number of work week columns, but it will default to the most recent 9 work weeks. (Was that last part even relevant?)
Dimensions:[OrderDate].[Work Week Calendar].[Work Week] (My report should only show the work week, not individual dates); [Customers].[Customer Name], [Customers].[Country] (There are about 8 separate countries, but I only use 2 in the example T-SQL code below)
Measure: [Order Amount] (Any value > 0 suggests an order was placed)
The final SSRS report will be a line chart with a line for each of the different countries. The bottom legend will be work weeks and the values of each line for each work week will be the number of customers in that country that placed at least one order during that particular work week.
Since I'm not sure how exactly to phrase the question any better than "how many customers had at least one order each week during the previous 9 weeks," you can see what I'm after in the following T-SQL: the "Totals" column.
Could somebody please assist? Thanks.
-Eric
-------------------------------------------------------------------------------------------------
DECLARE @example TABLE (
Customers varchar(10)
, [WW1-US] int
, [WW1-UK] int
, [WW2-US] int
, [WW2-UK] int
, [WW3-US] int
, [WW3-UK] int
)
INSERT INTO @example VALUES
('Cust X', 5, NULL, 3, NULL, 9, NULL)
, ('Cust Y', NULL, 13, NULL, NULL, NULL, 4)
, ('Cust Z', 6, NULL, 13, NULL, 16, NULL)
, ('Totals', 2, 1, 2, 0, 2, 1)
SELECT * FROM @example WHERE Customers = 'Totals'