As floats and ints can just be summed, I do not think there is anything special needed for Measure1
and Measure2
. Assuming that the empty fields in you sample table are null
s, you even do not need the measure_type
column for anything, as summing across nulls is fine, i. e. you could collaps your fact table to one third of its size by coalescing the three records for different measure types to one, and omitting the null
values.
Thus, we are left with the aggregation of the string values. As strings cannot be used as physical measures, we must put this column in an attribute and implement the aggregation as a calculated measure. To do this, you can proceed as follows:
- Create a dimension table with just a numeric primary key column and the distinct values from the text value column. I would suggest to also add a record with a special text like
'<n/a>'
to this table, for cases where there is no text_value for a combination of dim1 and dim2. It is generally a good idea to avoid null attribute values and null foreign keys in Analysis Services. - Add a foreign key to the fact table referencing this dimension from each record.
- In BIDS, create the dimension, let's name it
text
and I am assuming that the attribute is calledtext value
. Set the reference between the measure group and the dimension in Cube Editor. - Define a calculated measure for
Measure3
with the following expression:
.
Generate( (EXISTING [text].[text value].[text value].members )
- { [text].[text value].[<n/a>] }
as a,
a.Current.Name,
', '
)
- Make the dimension or the attribute invisible.
Of course, you need not create the dimension table and the foreign keys in the fact table physically.You can as well generate them as views or named query in the Data Source View.
And you can use a different delimiter than the comma and space which I used, this is the third argument to the Generate
MDX function.