Measure between dimension dates

Hi

I have to take the amount from the fact table only when the date(fact) is between start date and end date of dimension table.

My Dimension

P ID

Start Date

End Date

10

01/01/2013

01/12/2013

20

01/01/2013

01/12/2013

30

01/01/2013

01/12/2013

Fact

March 23rd, 2014 4:47am

Try the below:

Select A.* From Dimension A

Inner Join Fact B on A.ID = B.ID

where B.Date between A.Startdate and A.EndDate

Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2014 4:55am

One more method:

Select A.* From Dimension A

Where exists( Select 1 From Fact B on A.ID = B.ID

where B.Date between A.Startdate and A.EndDate)

March 23rd, 2014 4:57am

Hi Royal,

According to your description, you want to filter the data base on the StartDate and EndDate, right? In this case we can use STRTOMEMBER function to achieve the requirement. Here is a sample query for AdventureWorks cube for your reference.

select
{[Measures].[Internet Sales Amount]
} on columns,
{[Date].[Date].members} on rows
from(
select
(
STRTOMEMBER("[Date].[Date].&["+@StartDate+"]"):STRTOMEMBER("[Date].[Date].&["+@EndDate+"]")
) on columns
from [Adventure Works]
) 

Reference:StrToMember (MDX)

Regards,

Free Windows Admin Tool Kit Click here and download it now
March 24th, 2014 5:22am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics

ID

Date

Amount

10

01/10/2013

100

20

01/10/2013

100

30

01/10/2013

100

10

01/01/2001

10

20

01/01/2001

10