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
92 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
need help in sql 4 66
SQL Select Statement 2 22
SQL Server Question 5 28
SSRS troubles 4 20
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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

895 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now