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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

757 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