Using Google Sheets, I am trying to figure out how to count the number of values that fall in a specific date range (within a week of today). In column A I have dates, and column B I have fruits. I want to see how many bananas are within a week of Today (ex. Today minus 7 days).
See attached picture with my layout.
Currently I am using the formula:
=countifs(B2:B21, "Banana", A2:A21, (B23-7))
where B23 is today's date. The formula says there's only 1 Banana value, when I know there should be more.
You would need to slightly adjust your formula to:
=COUNTIFS(B2:B21, "Banana", A2:A21, ">"&B23&-7)
If you want to always get last week's count, you could use the following
=COUNTIFS(B2:B21, "Banana", A2:A21, ">"&(TODAY()-7))
Functions used:
COUNTIFS
Related
I have a google spreadsheet with dates that are in the future as well as in the past and am trying to countifs all the dates that are within the last 7 days and NOT the dates in the future.
That is where ">"TODAY()-7 comes in.
I have been trying to use =COUNTIFS(VALUES!A:A,">"&TODAY()-7,VALUES!B:B,"SCHEDULED") but this counts the dates for the future as well.
Would I add something that counts the dats inbetween two other values?
Here is a spreadsheet for this problem.
Updated
The following formula will count the number of instances when column a is a in a range of including today and 7 days back AND column B corresponding value ="Scheduled". Note that the iferror will be necessary to account for a blank returned filter.
=if(ISERROR(FILTER(A:A,A:A<=today(),A:A>=Today()-7,B:B="SCHEDULED")),0,
counta(FILTER(A:A,A:A<=today(),A:A>=Today()-7,B:B="SCHEDULED")))
Since the above formula has a relative value (today()), one can test with this hardcoded formula to the below dataset:
=if(ISERROR(FILTER(A:A,A:A<=date(2022,12,15),A:A>=Today()-7,
B:B="SCHEDULED")),0,counta(FILTER(A:A,A:A<=date(2022,12,15),
A:A>=date(2022,12,15)-7,B:B="SCHEDULED")))
Column A
Column B
12/4/2022
NOT
12/5/2022
SCHEDULED
12/6/2022
NOT
12/7/2022
SCHEDULED
12/8/2022
SCHEDULED
12/9/2022
NOT
12/10/2022
SCHEDULED
12/11/2022
NOT
I have 2 rows. One row has dates and the other row has numbers.
I want to build a google sheet formula that allows me to sum 10 days after the next Saturday. So if today is Monday 7/22/2019, I want the sum from Sunday (7/28/2019) through and including the next 9 days. If today was Tuesday (7/23/2019) the formula would return the same result, because it's always starting from the next Sunday.
Another way I'm looking at it is the sum of the 10 days after the current week number since google has the weeks beginning with Sunday.
Thanks for your help.
My current array formula is using weeknumber:
sumifs(rowwithnumbers,weeknum(rowwithdates),">"&weeknum(today()),weeknum(rowwithdates),"<="&weeknum(Today())+2))
but that gives me the next 14 days, which is close but not exactly what I want. I don't want to sum the next 2 weeks after the current week, I want to sum the next 1o days after the current week.
=ARRAYFORMULA(SUM(INDIRECT(
ADDRESS(2, MATCH(VLOOKUP(WEEKNUM(TODAY())+1, {WEEKNUM(ROW(INDIRECT(
"A"&DATEVALUE(TODAY())&":A"&DATEVALUE(TODAY()+8)))),ROW(INDIRECT(
"A"&DATEVALUE(TODAY())&":A"&DATEVALUE(TODAY()+8)))}, 2, 0), 1:1, 0), 4)&":"&
ADDRESS(2, MATCH(VLOOKUP(WEEKNUM(TODAY())+1, {WEEKNUM(ROW(INDIRECT(
"A"&DATEVALUE(TODAY())&":A"&DATEVALUE(TODAY()+8)))),ROW(INDIRECT(
"A"&DATEVALUE(TODAY())&":A"&DATEVALUE(TODAY()+8)))}, 2, 0), 1:1, 0)+9, 4))))
Although you could put it all in one formula, I think for clarity and debugging it would be good to use a separate sheet (call it "Dates") for the date calculations. Then use the results of the date calculations as arguments to your SUMIFS function.
In that case, the date calculation for the next Saturday is:
=IF(WEEKDAY(TODAY()) = 7, TODAY() + 7, TODAY() + 7-WEEKDAY(TODAY()))
That checks if today is a Saturday, and if it is, uses today plus 7 days. Otherwise, it just adds the number of days until the upcoming Saturday. If you store that cell in B2, for example, then you can calculate your end date with a simple:
=B2+10
If you store that in C2 of the "Dates" Sheet, and your value list is in a Sheet called "Values" with dates in column A and the numbers in column B, then your sum function is:
=SUMIFS(Values!$B:$B,Values!$A:$A, ">= " & Dates!B2, Values!$A:$A, "<= " & Dates!C2)
Here is a link to a Google Sheet showing all of above: Google Sheet
I want to get number of months user selected using Relative Dates Filter?
If user entered "Last 3 Months" then I wants to get number of days for 3 months to use these days in another calculated field.
Calculated field which is using this is as follows.
([Total Sale within Entered Date]/[Number of Days])*365
which returns me predicted sales for the whole year.
Here, [Number of Days] is the filter which I am using. Picture added for Relative Dates filter I am using.
Screenshot of Relative Date Filter:
You need to create a calculated field that works out the number of days in the data.
Something like datediff('day',min([dates]),max([dates])) if data is present for all the days in the time period will work. This calculation will dynamically give you the number of days between the first and last date in the [dates] field for whatever data is selected by the filter (so won't be precise if not all the possible dates are represented in the dataset).
Could someone please explain me creating BINS based on Weekdays in Tableau? I tried creating different Calculation Fields but it won't work
You're working too hard.
Tableau already knows how to bin values by dates at many levels of granualarity: such as year, month, day, weekday, hour etc. So you don't need to create a new field to bin dates by the day of the week. (creating bins is not difficult, it's just already available in this case)
Just put a discrete (blue) date or datetime field on a shelf. You'll see the date level of granularity displayed like, say, YEAR(MyDateField) with a leading plus sign.
You can either
click on the plus sign to drill down by adding a second level, say MONTH(MyDateField)
or
right click on the field to select the date level of granularity you want
Alex's Answer is exactly correct, Tableau will perform the operation automatically. What is great about is that you can select various formats (Full day name, number, 1 letter or 3 letter day etc.).
However if you absolutely need to you can used this formula:
datepart('weekday',[Date])
to give you the 1 (Sunday) to 7 (Saturday) value if you need it for something other reason, say another calculation.
I have a report I am trying to modify in Crystal. It has a data field that has a formula in it, but I want to use another formula.
This is an example of what I am trying to do.
[((# Days in January) – 15) x (Market Rent/(# Days in January))]
+ [((# Days in February) – 0) x (Market Rent/(# Days in February))]
+ [14 x (Market Rent/(# Days in March))]
I have ADO commands built out for the market rent, and a start date and end date. The months in my example are just that an example. I am not sure how to take my ADO command dates that are entered in on a filter page, and put them in a formula like the one above. Any ideas?
Also, in the first and last para. the -15 and the 14 are for a date in the middle of the month. So if the start date was on the 15th of Jan, and the End date was the 15th of march. This formula would calculate my loss of rent during vacancy.
If I'm reading your question correctly, you want to take a date field and find out how to measure the number of days in that month, the month before it, and the month after it. Here's some Crystal formulas to help you out. Let's assume your date field is called {#DateFld}:
To find the number of days in a particular month relative to a particular date, try this:
local datevar X:=cdate(dateadd("m",0,{#DateFld}));
datediff(
"d",
date(year(X),month(X),1),
date(year(X),month(X)+1,1)
)
I recommend you copy & paste this in 3 different formulas:
- In the 1st formula, replace the "0" with a -1 to get the number of days in the previous month.
- In the 2nd formula, don't change anything. That'll get you the number of days in the current month (i.e. the month that {#DateFld} is in)
- In the 3rd formula, replace the "0" with a +1 to get the number of days in the next month.
For example, if {#DateFld} is March 10th, 2011, the 1st formula will give you 28, the 2nd will give you 31, and the 3rd will give you 30.