Solved

Find last month with data

Posted on 2010-09-03
11
918 Views
Last Modified: 2016-02-15
I am trying to create an MDX query that will return the last month with data from the cube.  The problem is that there are zeroes loaded into the months where there is no data.  I have attached the query I am trying to use but it always returns the last month of the year and shows 0 as the measure.
SELECT { parallelperiod([Fiscal Year FMP].[Fiscal Year].[FY],1,closingperiod([Fiscal Year FMP].[Fiscal Year].[Mth], [Fiscal Year FMP].[Fiscal Year].defaultmember)),closingperiod([Fiscal Year FMP].[Fiscal Year].[Mth], [Fiscal Year FMP].[Fiscal Year].defaultmember) } ON COLUMNS ,



{ DESCENDANTS( [FMP_Facility].[FMP_Facility].[Level ID].&[STATION].&[V20], [FMP_Facility].[FMP_Facility].[Division] ) } ON ROWS  



FROM [FMP] 



WHERE ( [Category].[Category].[Cat Desc].&[112 ARS NONCUM COLLECTIONS/CUM COLLECTIONS], [Measures].[Numerator] )

CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL

Open in new window

0
Comment
Question by:vincem1099
11 Comments
 
LVL 7

Expert Comment

by:d507201
ID: 33601360
Wow, good stuff.  I've gotta learn something about MDX queries.
0
 
LVL 7

Author Comment

by:vincem1099
ID: 33619972
It would be better stuff if I could figure out how to determine the last month without a 0 loaded into the data.
0
 
LVL 9

Expert Comment

by:radcaesar
ID: 33631048
0
 
LVL 7

Author Comment

by:vincem1099
ID: 33631216
That solution is for a 12 month period not for the last period with data
0
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 33637151
0
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

 
LVL 7

Author Comment

by:vincem1099
ID: 33663532
That will find the maximum amount but not the last period without 0 for data
0
 
LVL 11

Expert Comment

by:theartfuldazzler
ID: 33681115
Under SQL I would try something like:

SELECT MAX(Case when Var ne 0 then Month else 0 end) as Last_Month

Not sure if the same will work for MDX.
0
 
LVL 7

Author Comment

by:vincem1099
ID: 33717561
I think a filter function needs to be used but I am having trouble with the syntax.  This code gives me the error that  a level expression is expected but  a tuple was used:
SELECT { parallelperiod([Fiscal Year FMP].[Fiscal Year].[FY],1,closingperiod(filter([Fiscal Year FMP].[Fiscal Year].[Mth],[Measures].[numerator]<>0), [Fiscal Year FMP].[Fiscal Year].defaultmember)),closingperiod([Fiscal Year FMP].[Fiscal Year].[Mth], [Fiscal Year FMP].[Fiscal Year].defaultmember) } ON COLUMNS ,



{ DESCENDANTS( [FMP_Facility].[FMP_Facility].[Level ID].&[STATION].&[V20], [FMP_Facility].[FMP_Facility].[Division] ) } ON ROWS  



FROM [FMP] 



WHERE ( [Category].[Category].[Cat Desc].&[112 ARS NONCUM COLLECTIONS/CUM COLLECTIONS], [Measures].[numerator] )

CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL

Open in new window

0
 
LVL 7

Accepted Solution

by:
vincem1099 earned 0 total points
ID: 34537096
Apparently the data cube was updated while this question was open so that the default member for the month hierachy was adjusted to the current month so this MDX query returns the current month with data without having to address the original problem:
 
SELECT { [Fiscal Year FMP].[Mth].defaultmember } ON COLUMNS ,

{ DESCENDANTS( [FMP_Facility].[FMP_Facility].[Level ID].&[STATION].&[V20], [FMP_Facility].[FMP_Facility].[Division] ) } ON ROWS  

FROM [FMP] 

WHERE ( [Category].[Category].[Cat Desc].&[112 ARS NONCUM COLLECTIONS/CUM COLLECTIONS],[Measures].[numerator] )
CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL

Open in new window

0
 
LVL 7

Author Closing Comment

by:vincem1099
ID: 34618301
Problem resolved by Cube Data changing.  Original problem never really resolved.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

743 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

11 Experts available now in Live!

Get 1:1 Help Now