user1054844
user1054844

Reputation: 972

ssas value between two dates

I am trying to fetch the sums of tot_ack on MDX, so it would be shown on erit dimension and acc (account dimesion). However I can not figure out how to model the between dates. I am new to MDX.

 select  SUM(tot_ack)    from
DBO.DIM_OBJ_ACC AS ACC INNER JOIN
 DBO.FAKTA_SALDO AS saldo ON ACC.ACC_ID = saldo.ACC_ID INNER JOIN
 DBO.DATE_OBJ_KP AS KP ON saldo.KP_ID = KP.KP_ID INNER JOIN 
   DBO.PERIOD AS PERIOD ON saldo.PERIOD = PERIOD.PERIOD
where   
 ACC.ACC _ID = '3001' and ACC.erit_ID = '1'
   (DATEADD(day, 0,DATEADD(month, 11,DATEADD(year,2011-1900, 0))) BETWEEN KP.KP_DATE_START AND KP.KP_DATE_END) AND 
     (PERIOD.MONTH= 12 OR PERIOD .MONTH=0) AND (PERIOD.YEAR =2011)  

My MDX-code

  SELECT {[DIM OBJ ERIT].[ERIT ID].MEMBERS}    ON COLUMNS,
    {[DATE OBJ ACC].[ACC ID].members} ON ROWS
    FROM [REPORT]
WHERE  (Measures.[tot ack],
    [PERIOD].[year].[2011],
    [PERIOD].[month].[12],  
    [DATE OBJ KP].[KP DATE START].[Year].[2011],
    [DATE OBJ KP].[KP DATUM END].[Year].[2011]
    )

Upvotes: 0

Views: 177

Answers (1)

MoazRub
MoazRub

Reputation: 2911

In mdx you specify range with ":". So your query should be

SELECT {[DIM OBJ ERIT].[ERIT ID].MEMBERS}    ON COLUMNS,
    {[DATE OBJ ACC].[ACC ID].members} ON ROWS
    FROM [REPORT]
WHERE  (Measures.[tot ack],
    [PERIOD].[year].[2011],
    [PERIOD].[month].[12],  
    [DATE OBJ KP].[KP DATE START].[Year].[2011]:[DATE OBJ KP].[KP DATUM END].[Year].[2011]
    )

Take a look at the example below

select 
[Measures].[Internet Sales Amount]
on columns,
[Product].[Category].[Category]
on rows 
from [Adventure Works]

Result enter image description here

Now lets filter it for 2013 -01-01 to 2013-01-10

select 
[Measures].[Internet Sales Amount]
on columns,
[Product].[Category].[Category]
on rows 
from [Adventure Works]
where 
[Date].[Date].&[20130101]:[Date].[Date].&[20130110]

Result enter image description here

Upvotes: 1

Related Questions