How to get data from current period -1 of current period




I need to get data from Aug 21 to Sept 21, but i dont want to use "Previous month", if not something like "current month -1", it´s possible?




Best Answer



    @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!!
  • Hi Luis,
    Misbah has given the best solution to this question on your other thread and when Misbah says something, Anaplan usually obliges 🙂
  • @ankit_cheeni  haha! 


  • friedaritter
    edited September 2023

    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 in date_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 in date_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 and date_column placeholders in the query to match your specific table and column names.