Solved

Find prevoius date with data

Posted on 2011-03-02
2
573 Views
Last Modified: 2013-11-16
Folks,

I am trying to create what seems to be a pretty simple calculated member, which will go back (from my current date) and find the previous date with any data entered (some of the dates have no info entered).  I am using recursion as follows:

with 
	member [Date].[Calendar].[BeforeCurrentWithData] as 
		iif( 
			([Date].[Calendar].currentmember.prevmember, [Measures].[Sales]) <> 0, 
			 [Date].[Calendar].currentmember.prevmember, 
			 [Date].[Calendar].[BeforeCurrentWithData]
		  )
select 
	{[Date].[Calendar].[BeforeCurrentWithData]} on columns,
	[Date].[Calendar2].[Date].members on rows
from [MyCube]
;

Open in new window

0
Comment
Question by:ISALRW
2 Comments
 
LVL 10

Assisted Solution

by:itcouple
itcouple earned 25 total points
ID: 35025034
Hi

The way I would do that. I would identify current date (I use VBA MDX functions) and filter for non empty based on measure group and take the first one using tail function.

There might be a better way of doing that. Maybe some last non empty but I'm sure.

Hope that gives you more options to experiment with
Regards
Emil

0
 
LVL 9

Accepted Solution

by:
Hwkranger earned 25 total points
ID: 35307492
You can use LAG or PARRALLEL PERIOD  take your pick.

http://msdn.microsoft.com/en-us/library/ms144866.aspx
http://msdn.microsoft.com/en-us/library/ms144866.aspx

See below for a example, I use both Lag and ParallelPeriod:
CREATE MEMBER CURRENTCUBE.[MEASURES].[Closed Relationship - STLY (Complete)]
 AS SUM(
	FILTER
	(EXISTING([Geography].[Agency].[Agency]),
	[Geography].[Import Start Date].CURRENTMEMBER.MEMBERVALUE <=
	HEAD(EXISTING [Date].[Date].[Date]).ITEM(0).ITEM(0).LAG(365).MEMBERVALUE
    ),
    Aggregate(Generate(EXISTING [Date].[Calendar].[Month].Members, {ParallelPeriod([Date].[Calendar].[Year], 1)}), [Measures].[Closed Relationship])
), 
FORMAT_STRING = "#,#;(#,#);0;\-", 
VISIBLE = 1;

Open in new window

CREATE MEMBER CURRENTCUBE.[MEASURES].[Closed Relationship - STLY (Complete)]
 AS SUM(
	FILTER
	(EXISTING([Geography].[Agency].[Agency]),
	[Geography].[Import Start Date].CURRENTMEMBER.MEMBERVALUE <=
	HEAD(EXISTING [Date].[Date].[Date]).ITEM(0).ITEM(0).LAG(365).MEMBERVALUE
    ),
    Aggregate(Generate(EXISTING [Date].[Calendar].[Month].Members, {ParallelPeriod([Date].[Calendar].[Year], 1)}), [Measures].[Closed Relationship])
), 
FORMAT_STRING = "#,#;(#,#);0;\-", 
VISIBLE = 1;

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

9 Experts available now in Live!

Get 1:1 Help Now