Search code examples
datecrystal-reports

Dates from the last month of specific ranges


How can I extract data from the previous month into three sections? I can use the function LASTMONTH but that gives me the whole month.

I need it split into three sections:

1st - 10th of last month
11th - 20th of last month
21st to end of last month

Solution

  • Sounds like a two step problem:

    1. Write a formula which comes up with 3 values based on date
    2. Group and Sort your data based on that formula

    The formula in question will look something like the following:

    IF {yourDate} in date(year(currentdate),month(currentdate)-1, 1) to date(year(currentdate),month(currentdate)-1, 10)
    THEN "A"
    ELSE IF {yourDate} in date(year(currentdate),month(currentdate)-1, 11) to date(year(currentdate),month(currentdate)-1, 20)
    THEN "B"
    ELSE IF {yourDate} in date(year(currentdate),month(currentdate)-1, 21) to date(year(currentdate),month(currentdate),1)-1
    THEN "C"
    ELSE "D"
    

    Where A, B, and C are valid dates and D is all the invalid ones. Substitute as appropriate.