0

Just started to explore MDX. Can anyone help me to get below result.

Looking to build a MDX query which gives same out as below SQL query

select max(date),min(date) from Fiscal_calendar

Where : 1. Fiscal_Calendar is dimension in cube 2. date is the attribute

Kuntady Yathish
  • 49
  • 2
  • 10

2 Answers2

3

Min Date will be the First Child of the [All] member while Max Date will be the Last Child.

SELECT {Fiscal_Calendar.Date.[All].FirstChild, Fiscal_Calendar.Date.[All].LastChild} ON 1,
{} ON 0
FROM [YourCube]

Second last child:

Fiscal_Calendar.Date.[All].LastChild.Lag(1)
SouravA
  • 5,147
  • 2
  • 24
  • 49
0
SELECT {
        [Dimension - Fiscal Calendar].[Fiscal Quarter].members.item([Dimension - Fiscal Calendar].[Fiscal Quarter].members.count-2)
        ,[Dimension - Fiscal Calendar].[Fiscal Quarter].[All].firstChild
    } ON 1,{} ON 0 FROM [MyCube]

Thanks @SourabA. Above code worked out to me. Do let me know if any better approach

Kuntady Yathish
  • 49
  • 2
  • 10
  • Your answer is not consistent with the information you supplied. Also, you are basically doing the same thing as the answer I provided, in a slightly more complicated way. – SouravA Jan 09 '16 at 08:18
  • Might be.. @sourabA could you suggest a better code item to get secondlastchild.. I could not find a MDX keyword – Kuntady Yathish Jan 09 '16 at 08:25
  • There is no better approach unless you are open to making changes to the cube structure. I added something for the second last child in my answer which at best is an alternative. – SouravA Jan 09 '16 at 08:32
  • @reachyathish - you have reinvented Lag in your code! - stick to Sourav's suggestion. Why is the last member empty? This suggests a problem in your database. – whytheq Jan 10 '16 at 12:46