Solved

Find prevoius date with data

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Update Query 23 93
SQL Server Determine if date is recurrance date 3 47
Online Forms 6 52
Problems using Provider=OraOLEDB.Oracle via VBScript/Classic ASP 5 45
Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

911 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

22 Experts available now in Live!

Get 1:1 Help Now