Solved

Showing last three years dynamically with lastperiods

Posted on 2014-02-12
3
91 Views
Last Modified: 2016-02-18
I'm trying to get the last three years to show in my report, but when I try to use the .currentmember I get the error:"The CURRENTMEMBER function expects a hierarchy expression for the 1 argument. A member expression was used."

Here is my query where I hard code the year and it works. but I would like to have the lastperiod part something like:
LASTPERIODS(3, [Date].[Calendar].[Calendar Year].currentmember but that gives me the above error.

Any idea why this does not work?

SELECT
HIERARCHIZE( { LASTPERIODS(3, [Date].[Calendar].[Calendar Year].&[2010]) } ) * { [Measures].[Internet Sales Amount] }

ON COLUMNS,
[Product].[Category].[Category]
ON ROWS
FROM [Adventure Works]

Open in new window

0
Comment
Question by:gosi75
[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
3 Comments
 
LVL 20

Accepted Solution

by:
dsacker earned 500 total points
ID: 40182787
If you intentionally tagged your question with "MS SQL Server 2008," HIERARCHIZE did not exist then.
0
 

Author Comment

by:gosi75
ID: 40182797
Thanks for the reply, this was intentionally done so. How would I be able to rewrite my query instead of using HIERARCHIZE ?
0
 
LVL 20

Expert Comment

by:dsacker
ID: 40182883
Could you post a small sampling of the expected rows. Thanks. Also, we don't have cubes (per se) here, so aren't using SSAS. If I can help from a SSMS query point-of-view, I'm glad to. If someone else chimes in with an SSAS solution, please award them.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add a step to a system backup job 6 55
converting integer data type to time data type in sql 4 60
What is this datetime? 1 33
Complex SQL Server WHERE CLause 9 40
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.

752 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