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
121 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
[X]
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
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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can we attach PDF to table 2 46
mssql 7 32
Rewriting a simple query 2 33
Sql group by orderdate and ordertotal 3 10
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.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

739 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