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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2110 views
  • 6 likes
  • 2 in conversation