So it's been kind of a while since I've had to do much cube setup work and I'm really rusty - my current client is picky about how the model is designed and wanted me to build as many of these calcs in MDX as possible, rather than deriving them in the ETL as separate measures (which probably would have been easier). The basic structure is simple - for the sake of this example, assume a fact table with a single additive measure in it (basically just a row count), and then a handful of dimensions.
The problem I have is that they define a ton of other "calculations" as a subset of this main row count and I could easily set up a query to return any of these numbers, but they want it built in as if these are all separate calcs.
So, the gist of it is, Calculated Measure A = Sum(Base Measure B) for all fact records that have Billing Dimension attributes D, E, or F.
If I were to do this in SQL, it'd probably look something like this:
SELECT SUM(f.MeasureBValue) CalculatedMeasureA FROM FactTable f JOIN DimBilling d ON f.DimBillingId = d.DimBillingId WHERE d.BillingAttributeName IN ('ValueD', 'ValueE', 'ValueF')
I started by using this, but this returns 0 if I'm not using [Billing].[Attribute] in my query, even with a default member of [Billing].[Attribute].[All]:
CREATE MEMBER currentcube.[Measures].[Calculated Measure A] AS iif([Billing].[Attribute].currentmember=[Billing].[Attribute].[A] or [Billing].[Attribute].currentmember=[Billing].[Attribute].[B] or [Billing].[Attribute].currentmember=[Billing].[Attribute].[C] ,[Measures].[Base Measure B] ,0 )
Then I tried this, but if I put [Billing].[Attribute].members on rows of my query, they all show the same constant number:
CREATE MEMBER currentcube.[Measures].[Calculated Measure A] AS Aggregate( {[Billing].[Attribute].[A],[Billing].[Attribute].[B],[Billing].[Attribute].[C]} ,[Measures].[Base Measure B] )
So... is there a better way to do this? Should I be summing/filtering perhaps?
Thanks in advance.
- Edited by Adam_Schmitt 16 hours 53 minutes ago