Calculate only date range.

I tried following this thread and it worked for the most part, but i'm not sure how to implement it in my scenario.


SUM formula needed for specific date rang… - Apple Community



I have a date column and a price column...



and I am calculating them here in a calendar view which is barrowed from the "Calendar Template" in which the month and year is a drop down...



Everything works. However, I want it to only calculate/show the days for that month (blue numbers) not the previous for next month (grey numbers).


Here's the formula i use in the currency cells...

MacBook Pro 15″, macOS 10.15

Posted on Jun 12, 2023 8:39 PM

Reply
Question marked as Top-ranking reply

Posted on Jun 13, 2023 3:27 AM

Assuming you have not modified the Month and Year table, it has the first day of the month in cell A4 and the last day in A6. I believe "B2" will always have a date in it (which is what is causing the problem to begin with) so the condition for your IF statement does not need to check for B2<>"", instead it needs to check the dates. The condition for your IF function will be


AND(B2≥Month and Year::$A$4,B2≤Month and Year::$A$6)


If you actually do need to check for B2<>"", you can use IFS


IFS(B2="","", AND(B2≥Month and Year::$A$4,B2≤Month and Year::$A$6), your_SUMIF_formula, TRUE,"")



7 replies
Question marked as Top-ranking reply

Jun 13, 2023 3:27 AM in response to Pique5

Assuming you have not modified the Month and Year table, it has the first day of the month in cell A4 and the last day in A6. I believe "B2" will always have a date in it (which is what is causing the problem to begin with) so the condition for your IF statement does not need to check for B2<>"", instead it needs to check the dates. The condition for your IF function will be


AND(B2≥Month and Year::$A$4,B2≤Month and Year::$A$6)


If you actually do need to check for B2<>"", you can use IFS


IFS(B2="","", AND(B2≥Month and Year::$A$4,B2≤Month and Year::$A$6), your_SUMIF_formula, TRUE,"")



Jun 14, 2023 4:11 PM in response to Pique5

In the formula you posted, you used D2 twice and B2 twice. If the formula is for column D, all should be D2. It also seems to me that the rows that are showing the date (row 2, row 5, etc) are always populated with a date so there is no reason to check if D2<>"", it will always be true. Or did you modify something where it might not fill in the date?


Jun 13, 2023 12:23 AM in response to Pique5

Hi Pique5,


I am having trouble understanding how you modified the Calendar.

Did you Merge some cells?

What is the purpose of rows 3, 5 etc.?


I am also having trouble understanding your overall aim:

However, I want it to only calculate/show the days for that month (blue numbers) not the previous for next month (grey numbers).


I tested your formula in a simpler document (no Calendar).

I turned off Menu > Numbers > General > Cell References: Use header names as labels. That makes it easier to construct and debug formulas.



The formula works.


Notes:

  • I formatted Date (Column B) in Table 1 as DD MMM YYYY to become more "international" for me and others who read this.
  • Day Only (Column A) in Table 2 is a Custom Format borrowed from the Calendar Template. It displays only the Day part of a Date & Time format, while storing the complete Date & Time.


Perhaps a look "behind the "curtain" in the Calendar Template will put us all on the same wavelength.

The Calendar Template is very cleverly designed, but parts are hidden.

Click on each table and Format > Table > Table Options > Tick Title to see the table name.




Click on the MONTH AND YEAR table and Menu > Table > Un-hide All Rows.


The dates in Calendar are Custom Format to display only the day. Edit Custom Format to see more "behind the curtain".



Regards,

Ian.

Jun 14, 2023 2:32 PM in response to Yellowbox

Yes based on that calendar i added some cells to suit my purpose. the one with the "1" and the one with "0.00" are the original cells.


So, in B4 i calculate anything from that date if it matches the month. But if the date is not in that month i don't want it to populate.


So in the previous screen shot the dates 29th, 30th, and 31st are not in June so the red and green cells below it should be blank. I even tried referencing the date range in the expanded Month and Year table to not show but couldn't get it too work.

Jun 14, 2023 5:01 PM in response to Badunit

Awesome seems to be working now. I did have them all pointing to D2 at one time, so changed it and it still didn't work. Then i noticed I left out the extra ", in the IFS and the TRUE at the end. Now only the days in the selected month (June) show. I confirmed by selecting the next month of July.



Curious, why B2="","", instead of D2<>"", ?


Thanks so much!

Jun 14, 2023 5:14 PM in response to Pique5

You could have written your IF formula that same way and swapped the if_true and if_false parameters. Often with IF, the thing you want it to do (the SUMIF) is the if_true parameter and if_false is a secondary thing so the condition is written with that in mind (if B2<>"" then...). I guess it is human nature to write it that way.


With IFS, the first test had to be for B2="" because the next condition (the AND with the date comparisons) will fail with an error if B2 is "" rather than a date.


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Calculate only date range.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.