MS Access Query - display data for each month over multiple years as columns - excel

OK, I am very new at this and have been googling things for the past few hours and have not found anything. Maybe I'm not looking for the right thing or I'm not looking hard enough but I am here now.
I have 3 calculations I need to do for each month (over 5 years) to be displayed as columns (3*12*5=180 total columns). I have mock formulas in Excel:
Fraction of Month =IF(AND(FEStart>=s01Y15,FEStart<=e01Y15),IF(FEStart=s01Y15, 1, ((e01Y15-(FEStart))+1)/DAY(e01Y15)),IF(AND(FEEnd>=s01Y15,FEEnd<=e01Y15),IF(FEEnd=e01Y15, 1, ((FEEnd)-(s01Y15))/DAY(e01Y15)),IF(FEEnd<=e01Y15, 0, IF(FEStart<=s01Y15,1,0))))
Year of Person =IF(AND(FEStart>=s01Y15,FEStart<=e01Y15),1,IF(AND(FEEnd>=s01Y15,FEEnd<=e01Y15),INT((s01Y15-FEStart)/365)+1,IF(FEEnd<= e01Y15, 0, IF(FEStart<=s01Y15,INT((s01Y15-FEStart)/365)+1,0))))
Monthly Salary =([Fraction of Month]*(SF/12))*(1.03^([Year of Person]-1))
Where
FEStart is the Start Date of the Person (entered by user)
s01Y15 is the start of the first month in 2015 (parameter set by me)
FEEnd is the End Date of the Person (entered by user)
e01Y15 is the end of the first month in 2015 (parameter set by me)
SF is the Annual Salary of the person (entered by user)
I understand that IF() has to be changed to IIF() and to use AS to name the field in the query for the sql code. However, I’m trying to see if I can make some sort of loop so I don’t have to manual change the variables and have 180 line written out. If I have to do that, I will. But I would really rather not.
Is there some way to use a while loop or for loop or some other loop to have MS Access create these 180 columns for me, without having 180 lines of code? Or do I just have to copy and paste a ton?
DISCLAIMER: I am using MS Access 2013. Also, I have some experience with VBA code in Excel (and I’m far more comfortable using Excel than MS Access) but am unsure of how to add VBA code to a query (I have added it to my forms).
I also had the idea to change the values of s01Y15 and e01Y15 in each loop but that might be a bit more complicated too so I just have (12*2*5=120) 120 variables set to the start and end dates of every month (which is probably not the best idea in retrospect). Anyways I still cannot get a loop to work in a query (if it even is possible).
EDIT: Not sure if this is helpful, but this is what I have:
Input data for People Table:
Person’s name (separated into f/l), Start/End Date (FEStart/FEEnd), Salary (SF).
People Query to show: Person’s name, Start/End Date (FEStart/FEEnd), Salary (SF), & the 180 columns I described above.
Restrictions on Calculations: Fraction of a Month should be a positive number no larger than 1. Year of person starts as a 1 and increases (by one) after each year (essentially infinitely but I am only doing 5 years – so with a max of 5). Monthly salary can be infinite.
Here is an example for an entry in the People table:
FName | LName | FEStart | FEEnd |SF
Anakin | Skywalker | 7/1/2017 |6/30/2019 |120,000.00
This is a little oversimplified because really the start and end dates are pulled form another table, connected by the “people id”.
Please see the link for the calculations.

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 - Photovoltaic - converting hours

I have a problem that I would like to solve. I got data in excel, which are
in this form, basically I have number of hours from 0 to 8760 in a column in excel, which represent the whole year. And in another column I have "Power from PV" which corresponds to how much power does photovoltaic system produce in that specific hour. I would like to convert these hours to months, so I could make a graph of monthly production of power in a whole year. Is there some sensible way to do this in excel?
Thank you for any suggestions.
You need three things:
You need to know that 1 equals 1 day, so if you want to convert hours into date related information, you need to divide it by 24.
There is a function, called Date(), which gives the date, based on year, month and day, like =DATE(2022,1,1).
There is a function, called Month(), which gives the month number of a date.
So, in summary, you need something like:
=MONTH(DATE(2022,1,1) + A3 / 24)
Once you have this in a new helper column, you can start using the Subtotals basic Excel feature.

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

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!

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)

Excel - Evaluate multiple cells in a row and create report or display showing lowest to highest

In an Excel 2003 spreadsheet, I have the top row of cells calculating the number of days and hours I have worked on something based on data I put in the cells below for each category. For example I enter the time spent on Programming, Spoken languages, house, piano, guitar...etc. The top cell in each category will keep track of and display how many days and hours I spent as I add the time spent for each category each day. I want to evaluate this top row and then list in a "report" (like a pop up box or another tab or something) in order from least amount of time to the most amount of time. This is so I can see at a glance which category is falling behind and what I need to work on. Can this be done in Excel? VBA? Or do I have to write a program from scratch in C# or Java? Thanks!
VH
Unbelievable... I've been scolded for trying to understand an answer and requested to mark this question answered. I don't see anything to do this and could not find anything that tells you how, so I'm just writing it here. MY QUESTION WAS ANSWERED... But thanks anyway...
Consider the following screenshot:
The chart data is built with formulas in columns H3:I3 and below. The formulas are
H3 =INDEX($B$3:$F$3,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
I3 =INDEX($B$2:$F$2,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
Copy down and build a horizontal bar chart from the data. If you want to change the order of the source data, use LARGE() instead of SMALL().
Alternative Approach
Instead of recording your data in a matrix, consider recording in a flat table with columns for date, category and time spent. That data can then easily be evaluated in many possible ways without using any formulas at all. The screenshot below shows a pivot table and chart where the data is sorted by time spent.
Edit after inspecting file:
Swap rows 2 and 3. Then you can choose one of the approaches outlined above.
Consider entering the study time as time values. It is not immediately clear if your entry 2.23 means 2 hrs and 23 minutes, or 2 hrs plus 0.23 of an hour, which totals to 2hrs, 13 minutes.
If you are using the first method, then all your sums involving decimals are off. For example, the total for column B is 7.73 as you sum it. Is that meant to be 7 hrs and 73 minutes? That would really be 8 hrs and 13 minutes, no? Or is it meant to be 7 hrs and 43 minutes? You can see how this is confusing. Use the colon to separate hrs and minutes and - hey - you can see human readable time values and don't have to convert minute values into decimals.

Resources