Solved

Showing last three years dynamically with lastperiods

Posted on 2014-02-12
3
80 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
  • 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now