I have three dimensions, a [Transaction]
, [Trade Date]
and [Report Date]
.
The [Transaction]
is related to both, and I would like to define a function for a KPI
in which I look for the following:
- For each date where there exists a trade in as a transaction, check from this date and a range that goes 30 days back for transactions where the difference between
[Trade Date]
and[Report Date]
is greater than 1. - I want to sum up the
[Measure].[N of Transactions]
in this range, for each trader on each date.
I've tried the following:
WITH
SET [Filtered] AS FILTER(NONEMPTY({[Trade Date].[Calendar].CurrentMember.lag(30):[Trade Date].[Calendar].CurrentMember}),
DateDiff("d",
CDate([Report Date].[Calendar].CurrentMember.MemberValue),
CDate([Trade Date].[Calendar].CurrentMember.Lag(1).MemberValue)
) > 1
)
MEMBER [Measures].[x] AS SUM([Filtered].CURRENTMEMBER, [Measures].[N of Transactions])
SELECT [Measures].[x] on 0,
[Transaction].[Trader].&[some_id_here] on 1
FROM [Relevant]
WHERE [Trade Date].[Calendar].[2014-02-16]
But this obviously doesn't work.
+----------------+
|factTransaction |
| |
+----+ +----+
+-------------+ | | | | +-------------+
|dimTradeDate | | | | | |dimReportDate|
| | | | | | | |
| +----- | | +----+ |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
+-------------+ +----------------+ +-------------+
Above is the structure in the designer. To sum it up, how do I write an MDX query that looks at each date, backtracks 30 days and creates a range. From this, look at all transactions and return the sum of the measure [Measures].[N of Transactions]
for that range and [Transaction].[Trader]
?