Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

MDX query that replaces hard coded year with current year, but if prior to January 15th use previous year

Posted on 2015-02-17
2
109 Views
Last Modified: 2015-02-18
How does one write a MDX query that replaces hard coded year with current year, but if prior to January 15th use previous year. Here is what I have below


SELECT NON EMPTY {
[Measures].[TCE],
[Measures].[Voyage Count],
[Measures].[PnL],
[Measures].[Voyage Result],
[Measures].[Net Days] } ON COLUMNS,
 NON EMPTY {
 ([Voyage].[Charterer].[Charterer].ALLMEMBERS ) }
 DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
 FROM ( SELECT ( [Top 10 Charterers] )
 ON COLUMNS FROM ( SELECT ( { [Date].[Year].&[2014] } )
 ON COLUMNS FROM [cubeVoyageResults]))
 WHERE (
   [Date].[Year].&[2014]
 )
 CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
0
Comment
Question by:pmauriello
2 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40615167
I don't use MDX, so all I'm attempting for you are some pointers (sorry, others may supply the bits I can't)

a. the function NOW() supplies the system date and you can then use YEAR() to extract just that part of the date.

This MS support article explains it see the example below
-- The First Calculated member is the value of NOW()
WITH  MEMBER [Measures].[Full Date] as 'NOW()'
-- The Second Calculated Member is the Day part of the first calculated member.
MEMBER [Measures].[What Day] as 'DAY([Full Date])'
-- The Third Calculated Member is the Month part of the first calculated member.
MEMBER [Measures].[What Month] as 'MONTH([Full Date])'
-- The Fourth Calculated Member is the Year part of the first calculated member.
Member [Measures].[What Year] as 'YEAR([Full Date])'
SELECT
   {[Full Date],[What Day],[What Month],[What Year]} ON COLUMNS
FROM Sales

b. for the wanted branch regarding the 15th of January you could use IIF()

see: https://msdn.microsoft.com/en-us/library/ms145994.aspx

hope this is a little helpful.
0
 

Author Closing Comment

by:pmauriello
ID: 40616464
Thanks that set me off in the right direction.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question