How to Sum Up Records in Multiple Columns in MS Access Table - sql

I have a table of Accruals by Month, with each Accrual in a separate row and the months across the top like the below.
There are also some non-numerical columns in the table such as Reference and Company as per the below.
Jan-16 Feb-16 Mar-16 Reference Company Total
Accrual 1 $100 $200 $300 x Z $600
Accrual 2 $150 $450 $550 y A $1,150
Accrual 3
Screenshot of Image
I want to put a Total Column at the end of the table that sums up all the monthly entries for each Accrual.
Bearing in mind that the number of monthly columns will increase by 1 each month and I don't want to have to manually change the formula to add the new month in each month.
Would be grateful for ideas on how to do this please?
Thanks

Related

how to create another dataframe from an existing one matching for multiple conditions

I have a dataframe that has around 8 million rows for housing data having values for zip, year and month for over 3 years. I want to create 4 separate dataframes for each year from this one that has columns for zip and month wise prices. In short I want to search for a particular zip for year 2019's January month and add the average price in front of it in another dataframe.

Calculating Weekly Returns from Daily Time Series of Prices v2

This is a slightly adjusted version of the question here: Calculating Weekly Returns from Daily Time Series of Prices which was answered by #Scott Craner:
I want to calculate weekly returns of a mutual fund from a time series of daily prices. My data looks like this:
A B C D E
DATE WEEK W.DAY MF.PRICE WEEKLY RETURN
02/01/12 1 1 2,7587 -0,0108
03/01/12 1 2 2,7667
04/01/12 1 3 2,7892
05/01/12 1 4 2,7666
06/01/12 1 5 2,7391
09/01/12 2 1 2,7288 0,0067
10/01/12 2 2 2,6707
11/01/12 2 3 2,7044
12/01/12 2 4 2,7183
13/01/12 2 5 2,7619
16/01/12 3 1 2,7470 0,0511
17/01/12 3 2 2,7878
18/01/12 3 3 2,8156
19/01/12 3 4 2,8310
20/01/12 3 5 2,8760
23/01/12 4 1 2,8875
The date is (dd/mm/yy) format and "," is decimal separator. This would be done by using this formula: (Price for first weekday of next week - Price for first weekday of current week)/(Price for first weekday of current week). For example the return for the first week is (2,7288 - 2,7587)/2,7587 = -0,0108 and for the second is (2,7470 - 2,7288)/2,7288 = 0,0067.
The problem is that the list goes on for a year, and some weeks have less than five working days due to holidays or other reasons. Some weeks start with weekday 2, some end with weekday 3. So I can't simply copy and paste the formula above. I added the extra two columns for week number and week day using WEEKNUM and WEEKDAY functions, thought it might help. I want to automate this with a formula and hope to get a table like this:
WEEK RETURN
1 -0,0108
2 0,0067
3 0,0511
.
.
.
I'm looking for a way to tell excel to "find the prices that correspond to the min weekdays of two consecutive weeks and apply the formula "(Price for first weekday of next week - Price for first weekday of current week)/(Price for first weekday of current week)".
I would appreciate any help! (I have 5 separate worksheets for consecutive years, each with daily prices of 20 mutual funds)
It seems to me that you can generate your column E with this formula in E2 :
=IF(B2=B1, "", (VLOOKUP(1+B2, B3:D9, 3, FALSE) - D2)/D2)
It's a VLookup limited on the next 7 rows from each row that declares a new week.
Copying into all cells will give the result indicated in your first tableau. To transform this result into to the list (Week, Return) is a matter of a filter that hides blanks from E.
Notice that a problem could occur if the WeekNum restarts from one when a new year is reached, but since you say that each of your sheets is for one (calendar) year, it shouldn't happen.

extracting common data of current months and last two monnth sql

I have a table with more than 20000 rows, In one of column i have month from jan 2014 to Dec 2014, and in another column i have a loan number. Most of the loan Numbers are reapeting every months,now i need to get only the loan Number which are apperead in all three monthy consecutively. For eg if i am getting data for current months i also wanted get data which are common in two months before the current months. The database that i m using is Access DB. Any adivice will be more than a help, Thanks in Advance.
SELECT Loans.LoanID, Sum(IIf([period]=[month],1,0)) AS CM, Sum(IIf([period]=[month]-1,1,0)) AS [m-1], Sum(IIf([period]=[month]-2,1,0)) AS [m-2]
FROM Loans
GROUP BY Loans.LoanID
HAVING (((Sum(IIf([period]=[month],1,0)))>1) AND ((Sum(IIf([period]=[month]-1,1,0)))>1) AND ((Sum(IIf([period]=[month]-2,1,0)))>1));
I used month as an integer, and didn't make any adjustment for months 1 and 2 to loop back and look at prior year - you should be able to modify this based on the actual format you are using for the month.

rearrange SQL data to different view

I have a database table with product, salesvolume, date and a timestamp in SQL server.
I have data in tables as:
date product time volume
10-28-2014 a 15:05 5
10-28-2014 a 16:06 8
10-28-2014 b 9:05 3
Required format:
date product h10 h16 h17
"10-28-2014" a 5 8
"10-28-2014" b 3
From this I want to create a new table/view in which I have total sales per day, per product, per hour of the day.
So i'll have 24 columns, 1 per hour of the day and one record for every day for every product.
Is this possible to create with just SQL? any tips how to do this?
Thank you!
I'm sorry but can't get the table layout to work...
You want to first of all group your data by day, hour (which you can extract from your time-stamp field), product and sum by sales.
From this you can then use the pivot function to cross-tab your hour field - you'll find plenty of documentation about the pivot functionality on-line.

SSRS - How to get subtotals for a set of 12 records in a column

I am novice with SSRS.
I have a report which should display 60 months (5 years displayed like Jan 1999, feb 1999 & so on till the end of 60 months) and its corresponding sales amount. I want to get averages for the first 12 months (i.e for the 1st year) and so on. Is it possible? My dataset just gives me all the 60 months row-by-row.I am using matrix for my report.
Thanks,
User007.
I would add some nested row grouping to the matrix. The higher-level group would be by year, which would allow you to have a row in the matrix that totals/averages all of the data for the year. The inner group would be by month, giving you the individual month rows as your dataset returns them.
Here is some information about defining and using groups