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
115 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:Paul Mauriello
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:Paul Mauriello
ID: 40616464
Thanks that set me off in the right direction.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

763 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