Ignore repeated days values using MDX - mdx

How can i ignore repeated days values using MDX ?
For example, from this:
12/1/1997
12/2/1997
12/3/1998
12/4/1999
To this:
12
I'm already tried use Distinct, but i'ts like they still considere as unique dates.
SELECT
{} ON COLUMNS,
DISTINCT([Time].[Weekly].[Day].Members) ON ROWS FROM [Sales 2]

These are different values and your cube treats them as such. I guess you can do some mimicing of that behavior with MDX by creating a MEMBER which has just the date part and doing distinct on that member. Something like:
WITH MEMBER [MonthPart] AS LEFT([Time].[Weekly].[Day].currentMember, 2)
SELECT
{} ON COLUMNS,
DISTINCT([MonthPart].Members) ON ROWS FROM [Sales 2]
Something like that but I am not sure for the correct syntax.
The proper way to fix that though is to create a good Time Dimension for your dates in the cube. There you can define hierarchies, levels and just take the [Month] part which will give you what you want (and will be much faster than writing complex MDX queries)

Related

MDX: Make Measure Value 0 based on flag

Would much appreciate any help on this.
I have a measure called "Sales" populated with values, however i am trying to turn the "Sales" value to 0, whenever the "Sales Flag" is set to 0.
Important Note: The Sales Flag is based on Date (lowest level of detail).
The difficulty that i am really experiencing and cant get a grip on, is how i am trying the display the MDX outcome.
As explained above, i would want to make the "Sales" value 0 whenever we have a 0 in the "Sales Flag" (which is based on the Date), but when I run the MDX Script I would wan't on the ROWS to NOT display the Date, but instead just the Week (higher Level to Date), as below shows:
I really have spent hours on this and can't seem to understand how we can create this needed custom Sales measure based on the Sales Flag on the date level, but having the MDX outcome display ROWS on Week level.
Laz
You need to define the member in the MDX before the select. Something like that:
WITH MEMBER [Measures].[Fixed Sales] as IIF([Sales Flag].currentMember=1,[Sales], 0)
SELECT [Measures].[Fixed Sales] on 0, [Sales Flag] on 1 from [Cube]
I am writing the code without SSAS here so it might not be the 100% correct syntax but you can get the general idea ;)
You can add the iif in the SELECT part but I find creating member to be the cleaner solution.
SELECT IIF([Sales Flag].currentMember=1,[Sales], 0) on 0, [Sales Flag] on 1 from [Cube]
If you have a control over the cube in SSAS you can create a calculated member there and you can access it easier.
Glad to hear if Veselin's answer works for you, but if not...
Several approaches are also possible.
Use Measure expression for Sales measure:
Use SCOPE command for Day level (if it's Key level of Date dimension). If it's not a key level you have to aggregate on EVERY level (week, year etc) to emulate AggregateFunction of Sales measure but with updated behavior for one flag:
SCOPE([Date].[Your Date Hierarchy].[Day].members,[Measures].[Sales]);
THIS=IIF([Sales Flag].CurrentMember = 1,[Measures].[Sales],0);
END SCOPE;
Update logic in DSV to multiply Sales column by SalesFlag. This is the easiest way from T-SQL perspective.

MDX (calculations) - count all clients accounts

I would like to count all clients accounts in my cube. I have created new calculation and I wrote a query in MDX langugage like:
COUNT(
[Client].[IdClient]
)
but when I would like to know how many accounts have, I always get '1' value instead e.g. '6000'.
This is my first time with MDX and OLAP Cubes.
What I supposed to do to get correct value?
Try this:
COUNT(
EXISTING [Client].[IdClient].[IdClient].Members
)
If you aren't happy with the performance of that then delete the calculated measure and replace it with a measure group built on the Client table. Build a Count measure.

Need date values which are 90 days or more from current date in MDX

I have a dimension [Date].[Last Met].
I need to pull out values which are more than 90 days from current date using MDX.
Please suggest the best way.
You can filter like this:
FILTER
(
[Date].[Last Met].MEMBERS,
Datediff("d",[Date].[Last Met].CurrentMember.Name, Format(Now(),'yyyyMMdd') <=90
)
A much more elegant option would be to create a calculated column in DSV called RollingLast90Days, and using SQL datediff logic to assign it 1/0. Once in place, you would need to just have a slicer :
...WHERE ([Time].[[RollingLast90Days].&[1])
Above is based on asumption you would process cube daily. If not apply the same logic in a calculated measure.
IIF(
Datediff("d",[Date].[Last Met].CurrentMember.Name, Format(Now(),'yyyyMMdd') <=90,
1,
null)
and then using this slicer on HAVING or in WHERE clause.

SSAS Daily Calculation Rolled up to Any Dimension

Im trying to create a daily calculation in my Cube or an MDX statement that will do a calculation daily and roll up to any dimension. I've been able to successfully get the values back, however the performance is not what I think it should be.
My fact table will have 4 dimensions 1 of which being daily date (time). I have a formula that uses 4 other measures in this fact table and those need to be calculated daily and then geometrically linked across the time dimension.
The following MDX statement works great and produces the correct value but it is very slow. I have tried using exp(sum(log+1))-1 and multiply seems to perform a little better but not good enough. Is there another approach to this solution or is there something wrong with my MDX statement?
I have tried defining aggregations For [Calendar_Date] and [Dim_Y].[Y ID], but it does not seem to use these aggregations.
WITH
MEMBER Measures.MyCustomCalc AS (
(
Measures.x -Measures.y
) -
(
Measures.z - Measures.j
)
)
/
Measures.x
MEMBER Measures.LinkedCalc AS ASSP.MULTIPLY(
[Dim_Date].[Calendar Date].Members,
Measures.MyCustomCalc + 1
) - 1
SELECT
Measures.LinkedCalc ON Columns,
[Dim_Y].[Y ID].Members ON Rows
FROM
[My DB]
The above query takes 7 seconds to run w/ the following number of records:
Measure: 98,160 records
Dim_Date: 5,479 records
Dim_Y: 42 records
We have assumed that by defining an aggregation that the amount of calculations we'd be performing would only be 42 * number of days, in this case a maximum of 5479 records.
Any help or suggestions would be greatly appreciated!

Pentaho CDF - MDX query: Showing data between months (parameters)

I have two parameters: 'from month' and 'to month'. I would like to show data between those months. This is my situation:
with member [Measures].[Ordercount Y-1] as '([Year].PrevMember, [Measures].[Ordercount])'
member [Measures].[Growth] as IIF([Measures].[Ordercount Y-1] >0,
[Measures].[Ordercount]/[Measures].[Ordercount Y-1] *100,0)
select {[Measures].[Growth]} ON COLUMNS,
NON EMPTY {[Year].[" +year+ "]} ON ROWS
from [Ordercube]
Its a dialchart, I want to show the % of sales compared to last year in combination with a range between months.
In SQL it would be easy: Where month >= frommonth and month <= tomonth.
Since you can only slice once in a MDX query I don't know what to do.
I hope someone can help me.
Thanks in advance
Actually, you'd find that SQL wouldn't be quite as easy if the months weren't both in the same year :)
Either way, what you're looking for is something like this:
select NON EMPTY {[Measures].[Quantity]} ON COLUMNS,
NON EMPTY [Markets].Children ON ROWS
from [SteelWheelsSales]
where {([Time].[2003].[QTR1] : [Time].[2004].[QTR2])}
This query was written against pentaho's data warehouse. I haven't the faintest clue what your data wharehouse looks like so I don't know what to use in the time dimension for your query, but it's the ([Time].[2003].[QTR1] : [Time].[2004].[QTR2]) syntax you're looking for, I think.
(disclaimer: I'm one of the CDF core developers, but my MDX sucks)
EDIT: In this particular case (Range Operator Reference) the reference site isn't particularly explicit, but the MSDN reference site for MDX is pretty good, so here's the general MDX Reference Site.