How to get data from current period -1 of current period
Best Answer
-
Hi @Luis98
Previous is the best way to go about it if you consider engine load on Anaplan but you can also use LAG or OFFSET. The least efficient would be to do a Month-1 and then lookup basis that.
There is a beautiful thread comparing these 4 functionalities which you can find here: https://community.anaplan.com/t5/Anaplan-Platform/Performance-Comparison-OFFSET-LAG-PREVIOUS-LOOKUP/td-p/51140
Let me know if this is helpful 🙂
0
Answers
-
@ankit_cheeni You are a genius, thank you very much!!! I have another question, if i want to pull the average of the previous 3 months, how can i do it? Regards!!1
-
Hi Luis,
Misbah has given the best solution to this question on your other thread and when Misbah says something, Anaplan usually obliges 🙂1 -
@ankit_cheeni haha!
1 -
Assuming you have a date column named
date_column
in your database table, you can construct a query like this to retrieve b2b data enrichment from August 21st to September 21st of the previous month:SELECT *
FROM your_table
WHERE DATE_SUB(CURDATE(), INTERVAL 1 MONTH) >= DATE_FORMAT(date_column, '%Y-%m-21')
AND CURDATE() < DATE_FORMAT(date_column, '%Y-%m-21');In this query:
CURDATE()
returns the current date.DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
subtracts one month from the current date, effectively giving you the first day of the previous month.DATE_FORMAT(date_column, '%Y-%m-21')
converts the date indate_column
to a string in the format 'YYYY-MM-21', where '21' represents the 21st day of the month.
The
WHERE
clause checks if the date indate_column
falls between the first day of the previous month (inclusive) and the first day of the current month (exclusive), effectively giving you data from August 21st to September 21st of the previous month.You can adjust the
your_table
anddate_column
placeholders in the query to match your specific table and column names.0