Solved

Find prevoius date with data

Posted on 2011-03-02
2
576 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

856 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