Get sum of cells containing "Vacation" except when related date matches certain day & month - excel

oversimplified i have two columns: Date and Text; I want to check my current amount of vacation days based on the first date in row 2, so i came up with the following formula:
="Available vacation days: "&YEARFRAC(A2;TODAY())*12*(25/12)
I calculate the fraction of the year based on the first date and todays date, multiply it by 12 to get months and multiply it again by the total amount of vacation days in my contract per month. Now i got another formula to collect me all cells in column B containing "Vacation", pretty straight forward:
=COUNTIF(B:B;"Vacation")
Now the interesting part - i got the formula who gives me a boolean if a datetime matches the 24th or 31st of december:
=AND(OR(DAY(A53)=24;DAY(A53)=31);MONTH(A53)=12)
I want to count vacation days happening on a 24th or 31st of december as a half-vacation day (0.5), and otherwise fully (as a 1). Then i want to combine my first statement with this result and subtract the used vacation days. I read about VLOOKUP and XLOOKUP but am unsure if this fits this purpose. I want to avoid having an extra column with my boolean returns and rather have this one cell giving me all the information combined.

Without introducing another column, and using DAY and MONTH
It's nearly impossible, and just unnecessarily so...
Please reconsider this, what will happen if you want to add 4th of July as a holiday?
Your formula =AND(OR(DAY(A53)=24;DAY(A53)=31);MONTH(A53)=12) only works for 1 row at a time. So, we can't ever use it with a list, because you will get the whole list as a result every single time. You can't divide them into smaller lists and join them together, there is no such functionality without VBA.
In the future, do not set arbitrary constraints like "no additional columns", you can hide them if you don't like them. And if you don't need them, remove unnecessary rows like non-vacation rows. They are irrelevant, so why not separate the two.
Just to prove my point, here's the solution you wanted:
Solution
=COUNTIFS(B2:B9;"Vacation") - (COUNT(IFERROR(FILTER(FILTER(FILTER(A2:A9;B2:B9="Vacation");MONTH(FILTER(A2:A9;B2:B9="Vacation"))=12);DAY(FILTER(FILTER(A2:A9;B2:B9="Vacation");MONTH(FILTER(A2:A9;B2:B9="Vacation"))=12))=31);0))+(COUNT(IFERROR(FILTER(FILTER(FILTER(A2:A9;B2:B9="Vacation");MONTH(FILTER(A2:A9;B2:B9="Vacation"))=12);DAY(FILTER(FILTER(A2:A9;B2:B9="Vacation");MONTH(FILTER(A2:A9;B2:B9="Vacation"))=12))=24);0))))*0,5
It works, but it's a pain to read, use and maintain.
A2:A9 refers to the dates column
B2:B9 refers to the text column
So in the future, the last thing you want to do is set arbitrary constraints. Furthermore, why use functions like MONTH and DAY when we can just read the text? That way you could even create a table of holidays to search for instead. That will be no fun task with this setup. (Oh, and if it's because of the year, just strip it away from the text when you want to know only the month and day.
Best of luck!

Related

Is a date within several date ranges

I'm trying to put together an excel spreadsheet to show the day-by-day impact of stays by 3rd country citizens in the EU's Schengen area (it's a fairly complex rolling 180 day window). At the moment, I have a column with every day from a start date (so lots of rows) and another where I enter a 1 if there was a stay in a Schengen country for that day. Then other columns calculate when the 180 day period started and how many days have been in Schengen for that day.
It's a bit of a faff having to enter a 1 for every day away. I'd like to have another worksheet where I simply enter the start and end dates of (an arbitrary number of) each stay and then the calculation spreadsheet simply works out if each date falls within a stay or not. Working out whether a date falls within one date range is pretty straightforward, but working out if it falls within several date ranges isn't obvious to me. Any suggestions please?
After a very fair comment, here's a couple of images that hopefully illustrate what I'm trying to do (please ignore the colours).
Example of date ranges, but the number of these should be arbitrary:
The calculated sheet - currently I have to enter the 1s individually whereas I'd like them evaluated from the date ranges:

Excel count number of dates (in rows) which fall under a predetermined period

So i have been playing with Excel for a while, and one thing led to another, i wanted to try this: How would i calculate the instances of dates (such as below) in one sheet
And count which of those dates fall under the 30/60/90 day period (such as below) I'm looking to see if i could have a final tally up the number of instances of dates which fall below 30/60/90 days to the current date in another sheet.
Using the table example gave that i would know that 2 dates fall under the 30/60 days period, and one fell under the 90 days period
Is there a solution to my predicament?
Edit: More accurate question
Use nested IF() function.
=IF(TODAY()-B2<=30,30,IF(TODAY()-B2<=60,60,IF(TODAY()-B2<=90,90,"Other period")))
Or try IFS() if you have Excel-365.
=IFS(TODAY()-B2<=30,30,TODAY()-B2<=60,60,TODAY()-B2<=90,90)
Another option is-
=XLOOKUP(TODAY()-B2,{30,60,90},{30,60,90},"Other Period",1)
You could try:
Formula in E2:
=SUMPRODUCT(--(CEILING(D$6-B$2:B$6,30)=D2))

How to reference one value to various cells, depending on a date?

Please have a look at the picture I attached, it'll make understanding my problem easier because it's hard to describe.
In the first table, I have capacity data for a product. The capacity changes by the date indicated in the column, i.e. from July 2017 the capacity would be 56, from December 2018 78, and from October 2019 99. The reason why I don't write down the capacity for every month is that I want to save columns.
In the second table, I have every month. I want to reference the correct capacity for each month, e.g. it would be 56 for every month until December 2018.
I have been considering an =INDEX function, but it seems to complex for that. Is there a way to reference like this without using VBA? Would the VBA solution be simple? Or am I forced to write a column for every month's capacity in the first table? Thank you!
https://i.imgur.com/mRoBtTo.png
You can simply use several IF statements to compare the month in your column with the months given in your first table, and put the value of the correponding month.
Let's admit your first row is 1 and first column is A, it should give something like:
= IF(D7>=$F$2; $F$3; IF(D7 >= $E$2; $E$3; IF(D7 >= $D$2; $D$3; "")))
I dont see you columns and rows so i hope you will change them correctly on this formula:
=HLOOKUP(C111,$C$106:$P$107,2,TRUE)
C111 is the cell above your red row.
$C$106:$P$107 is the tableof capacities, i know it is bigger then the current one so you see you can add more columns.
2 is the row number from the capacity table.
true is becouse you dont want it to be the exact value it will take the previews in hte order of items
Both previous answers work perfectly, but I would go this way-
You don't actually need an if to find the previous capacity. you can simply use the approximate match (similar to the hlookup answer) in an index formula
=+INDEX($B$4:$E$5,MATCH($B$9,$B$4:$B$5,0),MATCH(C9,$B$4:$E$4,1))
The product $B$9 matches exact (0), but the date C9 is bigger than or equal (1).
$B$4:$E$5 is the source of capacity and
C9:AF9 the date timeline
Final advantage would be that you can have several products to index, not only a single one.
Could you please try the below formula and provide feedback please?
=IF(AND(D8>=D2,D8<E2),"56",IF(AND(D8>=E2,D8<F2),"78",IF(D8>=F2,"99")))

How to filter data of last record of each week

I have a big data set of daily selling value of a particular ITEM. I want to know what was the price of ITEM on the last day of each week. Typically the last working day is Friday but if you don't have data for Friday then we need to get the previous working day data (Thursday).
Monday is considered the First day of week.
My Data looks something like this:
Data is in cells A2:C13.
My expected output is shown below:
Please help with VB macro or even simple excel formula.
You may want to try using a formula using the LOOKUP function, to search the list from bottom to top.
Afterward, a combination of INDEX and MATCH may get you on the right path as well.
Edit: I realize now that I was leading you astray because I thought you were asking something else! The most straightforward way I can see is as follows:
use WEEKDAY() to pull out the weekday values (as you did), except leave the values as numbers (with 1 being Sunday and 7 being Saturday).
Check each of these days to see if it precedes (i.e. has a lesser value) than the day above it. If not, we know that the week started over, and that cell is the last day of the week. Therefore, display its value.
Of course, this assumes that there are no Saturdays in your data - otherwise, Saturday would be listed as the end of the week. If you're crafty you can fix this dilemma though!
Thanks, Tyler.
Your suggestion helped me a lot in putting efforts in the right direction.
The way I did is as follows:
First I sorted my data in decreasing order of date so that I can have all the latest data at the top.
Range("AW4:BE999999").Sort Key1:=Range("BC4:BC999999"), order1:=xlDescending, Header:=xlYes
From Date created a string of "YEAR"&"WEEKNUM". This way I was able to group all the days in a specific week. Formula Used is:
=(TEXT(BC5,"yyyy"))&(TEXT(WEEKNUM(BC5),"00"))
Then I gave a unique Number to each record. The best way I could think of is to give the row number where record belongs.
=ROW(AY5)
Now using VLOOKUP function I got all the records matching string I have created in step 2
=VLOOKUP(AZ5,AZ:BD,5,FALSE)
I applied the above formula to get all the columns that I need.
Now I removed all the duplicate rows using below formula:
Cells.RemoveDuplicates Columns:=Array(1)
Now the remaining rows are the expected rows.
There may be a better way to do this but this is my first time with excel macro and formulas, so feeling happy.
Please comment other better ways to do this. It's always good to keep on improving our work.

Time series mock data generation for 16 years of quarterly data in Excel or Matlab

I would like to generate a mock time series quarterly dataset from, say, 2000-2016 for a variable (quarterly credit growth) that averages around a certain value (say, 30%). Can anyone give a suggestion on how to do this in principle?
Edit: what I was implying were the actual data values for each time period, i.e. data with a certain mean and variance.
Found a solution with a code in Matlab, for anyone interested, see below in answers.
Excel approach:
You can make column A your date list. In A1, or A2 or more if you have header rows, you will have to seed your list by providing the first start date. Lets assume you put your seed date in A2. I would then go about adding 3 month to you start date using a formula, and copy down until you have hit your desired date. In order to add the 3 months I would use the following in A3.
=date(year(A2),Month(A2)+3,day(A1)
that will give you the first day of the month every 3 months. If you want the first day of the month every 3 months, set the day to 1 like so:
=date(year(A2),Month(A2)+3,day(A1)
And end of month could be calculated as:
=eomonth(date(year(A2),Month(A2)+3,day(A1)),0)
however I would prefer to do the end of month calculation based on the row you are in so I would do it more like:
=EOMONTH($A$2,(rows($A$2:A3)-1)*3)

Resources