BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Melissak
Fluorite | Level 6

Hi, 

How to calculate the month to date period for the same period last year. 

 

Eg. If today is 13/05/2021 (Current Month to Date) how do I calculate what sales was for 1/05/2020 to 13/05/2020? 

1 ACCEPTED SOLUTION

Accepted Solutions
Melissak
Fluorite | Level 6

I managed to do this with the calculated item below:

 

IF ( ( Month('DATE X'n) = Month(DatePart(Now())) ) AND (
Year('DATE X'n) = Year(DatePart(Now()))-1 ))
DayOfMonth('DATE X'n) <= DayOfMonth(DatePart(Now())) ) )
RETURN 'VAUE X'n
ELSE 0

View solution in original post

5 REPLIES 5
Sam_SAS
SAS Employee

Hello,

 

You would use the ParallelPeriod operator in a calculated item.

 

Here is an example that should calculate the month-to-date value for the previous year:

 

ParallelPeriod(_Sum_, 'Expenses'n, _ApplyAllFilters_, 'Date'n, _ByMonth_, _ByYear_, -1, _ToDate_)

 

The last parameter above specifies the "to date" part.

 

The UI for the periodic operators in the graphical expression editor is a bit confusing, so refer to the doc and the tooltips.

 

Let us know how it goes.

 

Thanks,
Sam

 

Melissak
Fluorite | Level 6
Hi
I tried the above but it does the same calculation for every year in the data.
I want it to only return that value for the one month. (Last year, this month)
Sam_SAS
SAS Employee

Getting only a specific month is actually a bit trickier.

 

The easiest way might be to precalculate the value in your source table.

 

I am making some inquiries about a way to do it within VA.

 

Sam

Melissak
Fluorite | Level 6

I managed to do this with the calculated item below:

 

IF ( ( Month('DATE X'n) = Month(DatePart(Now())) ) AND (
Year('DATE X'n) = Year(DatePart(Now()))-1 ))
DayOfMonth('DATE X'n) <= DayOfMonth(DatePart(Now())) ) )
RETURN 'VAUE X'n
ELSE 0

Sam_SAS
SAS Employee
Great! Thanks for sharing your solution 🙂

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2040 views
  • 6 likes
  • 2 in conversation