Hello,
I need some help. I am quite new to MDX; I've created a cube and the measure needs to behave same as the MODE function in Excel (the followinglink describes what the function does). Apparently the only way of achieving this is by MDX (calling the MODE function directly from Excel is not an option for me). Practically the member should return a single value, that represents the price that appears most times. There are 4 dimensions in my cube: dates, stores, products and client products. I need the following calculations:
1. MODE(price) for specific Date, Product and Client Product. There will be multiple lines returned for this set, as there are multiple stores.
2. MODE(price) for specific Store, Product and Client Product. There will be multiple lines returned for this set, as there are multiple dates.
I found the below code online, that I've adapted to work against my cube, currently the query returns correct results for the first part, Mode(price) for multiple stores. I can change it to do the same for date.
What I need is to create 2 calculated measures using the last select and I am unsure how this can be achieved. Any help will be much appreciated or any other approach in achieving this.
WITH --Count how often each value appears MEMBER [Measures].[ValueCount] AS SUM( Union([Dim Stores].Store].CurrentMember.Level.Members, {[Dim Stores].[Store].CurrentMember} AS CurrentStore), IIF( ([Dim Stores].[Store].CurrentMember, [Measures].[Price]) = (CurrentStore.Item(0).Item(0), [Measures].[Price]) , 1, null)) --Only get the items that appear the most SET [MaxModes] AS ORDER(FILTER(NONEMPTY([Dim Stores].[Store].Members, {[Measures].[Price]}), [Measures].[ValueCount] = MAX(NONEMPTY([Dim Stores].[Store].[Store].Members, [Measures].[Price]), [Measures].[ValueCount])), [Measures].[Price], ASC) SELECT {[Measures].[Price]} on 0, [MaxModes] --Filter out the duplicates HAVING [MaxModes].CurrentOrdinal = 0 OR [Measures].[Price] <> ([Measures].[Price], [MaxModes].Item([MaxModes].CurrentOrdinal - 2)) ON 1 FROM [old_Prices_v2] WHERE {[Dim Date].[Date].&[2013-06-23T00:00:00]}*{[Dim Client Products].[Client Product].&[13]}*{[Dim Products].[Product].&[551]}