Sql Analysis Services Current Date

2019-03-02 14:09发布

问题:

I need to perform a calculation in SSAS which only applies to the current and future months (it can't be applied retrospectively using the available data).

I can do this by using the calendar hierarchy and hard coding today's month as follows...

SCOPE([Measures].[RollingStock]);        
    ([Dim Date].[Calendar].[Month].&[201008]:NULL) = 
    ([Measures].[Quantity On Hand] 
     - [Measures].[SO Open Quantity] 
     + [Measures].[PO Open Quantity] 
     - [Measures].[Forecasts Quantity]);        
END SCOPE; 

I want to replace 201008 with the current month (in that format).

Any ideas?

回答1:

CREATE SET CURRENTCUBE.[Current And Future Months]
 AS {
StrToMember("[Dim Date].[Calendar].[Month].&[" + Format(now(), "yyyyMM") + "]"):NULL
}