cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate Previous year in HANA

former_member182277
Contributor
0 Kudos

Hello,

I have the requirement to calculate the previous year?

How can i calculate the same under analytical view.

Regards,

Neha

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member615380
Discoverer
0 Kudos

For those who are still looking for an anwser alike;

get the date of today from 3 years ago;

format(addmonths(now(),-36),'YYYYMMDD')

Former Member
0 Kudos

Hi Neha,

Where you looking to do this calculation? In a formula? And when you say previous year, do you mean current year - 1 always?

The way I did it is in a calculated attribute of type INTEGER using this formula:

int(midstr(string(now()),0,4)) - 1

Thanks,

Anooj

former_member182277
Contributor
0 Kudos

Hello Anooj,

Yes i looking for the caluclation.

Senerio is:

i am having 2 year data, having A as measure.

if i select the period 2010001(YYYYMMM) then A values will visible.

Side bu side by want to create attribute/calculated measure where i can see the previous year data of A measure (2009001)

How can i acheive the same?

Regards,

neha

Former Member
0 Kudos

Ok. So I am assuming your period selection happens via an Input Parameter.

So within a calculated measure you could have something like this - I havent checked for syntax.

if((midstr("PERIOD",0,4) = midstr('$$INPUTPARAMETER$$',0,4) - 1),"A",0)

Basically use midstr() to get the year component from your period attribute and also your input parameter (convert both into string type if they are of a different type) . Do a  '-1' on your Input parameter value to get the previous year value and if they are both the same you assign the value of measure 'A' if not 0.

Ensure you get the data types right as well like how I have mentioned in my first response.

You could do this in multiple steps.. so a separate calc attribute for previous year based on your input parameter entry and then use the same within this calculated measure formula.

Ideally you would use restricted measures for this but I don't see a way to pass input parameter values into it at runtime.

Thanks,

Anooj

former_member182277
Contributor
0 Kudos

Hello Anooj,

Is &&Input Parameter&& reallly works?

I am having the select of the date at the reporting level not at the DB level?

Could you please sggest the other way to doing this.

Regards,

neha

Former Member
0 Kudos

Hi Neha,


Yes you can use Input Parameters in a formula.

If you are selecting the date at report level but want to restrict a measure by that date at the DB level you will need to pass that date value down to the database isnt it?What reporting tool are you using? You must be able to connect it to an input parameter on the analytical view...

If not you have to do this all at the report level itself.

Thanks,

Anooj

Former Member
0 Kudos

HI Anooj ,

I've a requirement similar to the one discussed here but I want to get the values for last 3 months from the month entered by the business through the Input parameter .

I've created 3 projections where each will take the value from input parameters and wanted to get month minus 1 , 2 and 3 respectively ,but I'm not able to achieve it through this :

if((midstr("PERIOD",5,6) = midstr('$$INP_CALMONTH$$',5,6) - 1),"A",0)

can you please help me in getting this ?

Also my Calmonth is a string do I need to convert it ?

Regards,

Akhilesh

Former Member
0 Kudos

HI Neha ,

I've a requirement similar to you,but I need to calculate the last 3 months .

Can you please help me on this ?

Regards,

Akhilesh

former_member184768
Active Contributor
0 Kudos

Hi Akhilesh,

Can you please open a new thread and provide an example of your Calmonth value. You mentioned it is a string input parameter value, so it can be manipulated by the string functions without need to convert to other data type.

Also confirm that the filter will be applied to the Calmonth column containing string data values.

Regards,

Ravi

Former Member
0 Kudos

HI Ravi ,

Opened a new string :

http://scn.sap.com/thread/3457680

Kindly have a look and suggest , help needed .

Regards,

Akhilesh