Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Find prevoius date with data

Posted on 2011-03-02
2
Medium Priority
?
581 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
[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 10

Assisted Solution

by:itcouple
itcouple earned 100 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

618 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