Variance File

vash011390

New Member
Joined
May 18, 2015
Messages
4
Hello All,

I am trying to create a Ms Access database that will generate an automatic variance explanation comparing two periods in two tables and the comparison in third table. This will help me eliminate the time spent on tedious (manual) comparison of various increases and decreases between lines. I don't know how to start - which query to use or maybe macro can help so I am seeking professional help.

Actually I already created .xlsm file with customized sumif but the file is soooo slow to generate variances...

A million thanks to all who will help.

Table 1

YearMonthChartlineCounterCounterNameBalance
201561000a1far200
201563000a1far150
201561000a1far40
201561000a2slow10
201562000a2slow30
201561000a3big500
201561000a3big100
201562000a2slow200
201565000a1far100
201562000a1far20
201561000a2slow10
201561000a1far10
201563000a3big70
201562000a1far50

<tbody>
</tbody>

Table 2

YearMonthChartlineCounterCounterNameBalance
201535000a1far200
201532000a1far100
201531000a1far20
201531000a2slow10
201533000a2slow10
201532000a3big70
201531000a3big50
201533000a2slow200
201531000a1far150
201531000a1far40
201532000a2slow10
201531000a1far30
201531000a3big500
201532000a1far100

<tbody>
</tbody>

Table 3

Pivot of the two tables and increase decrease.

Chartline1000
Sum of BalanceMonth
CounterCounterName36Inc(Dec)
a1far24025010
a2slow102010
a3big55060050
Grand Total800870

<tbody>
</tbody>
Explanation:
INCREASE $10 FAR, $10 SLOW, $50 BIG.

<tbody>
</tbody>
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
generate an automatic variance explanation comparing two periods in two tables and the comparison in third table.
Are you saying you want to store the results in a third table, or to compare table1 and table2 against table3? Or are you going to display the results in a form or report (usually best to do calculations in forms or queries, but I have not always adhered to that "rule of thumb")?
 
Upvote 0
Hello Micron,

Table 1 and Table 2 came from two different time periods.
The third table should contain the Variance Explanation after comparing the two but I do not know how.
The pivot only show the calculation differences between Table1 and Table2 but can be eliminated or just add another table to show this.

Hope I explained it clearly.
 
Upvote 0
I think you will need a union query that creates totals in order to get the records from each table into successive rows, then a cross tab query to arrange the rows into columns that resembles your pivot table. However, you cannot create a calculated field in a crosstab query to give you the difference, so you need a select query that uses the crosstab as a source. Someone may post an eaiser way than my solution, but here are sql statements that you can play with if they are not quite right:

qry1 - 1st part of union query (put the ; back on to run this as a separate query)
Code:
SELECT Table1.Year, Table1.Month, Table1.Counter, Table1.CounterName, Sum(Table1.Balance) AS SumOfBalance
FROM Table1
GROUP BY Table1.Year, Table1.Month, Table1.Counter, Table1.CounterName, Table1.Chartline
HAVING (((Table1.Chartline)=1000))
ORDER BY Table1.Month

qry2 - 2nd part of union query (remove the UNION to run this separately, ORDER BY can only be in 1st part)
Code:
SELECT Table2.Year, Table2.Month, Table2.Counter, Table2.CounterName, Sum(Table2.Balance) AS SumOfBalance
FROM Table2
GROUP BY Table2.Year, Table2.Month, Table2.Counter, Table2.CounterName, Table2.Chartline
HAVING (((Table2.Chartline)=1000));

qry3 - the concatenated union query
Code:
SELECT Table1.Year, Table1.Month, Table1.Counter, Table1.CounterName, Sum(Table1.Balance) AS SumOfBalance
FROM Table1
GROUP BY Table1.Year, Table1.Month, Table1.Counter, Table1.CounterName, Table1.Chartline
HAVING (((Table1.Chartline)=1000))
ORDER BY Table1.Month
UNION 
SELECT Table2.Year, Table2.Month, Table2.Counter, Table2.CounterName, Sum(Table2.Balance) AS SumOfBalance
FROM Table2
GROUP BY Table2.Year, Table2.Month, Table2.Counter, Table2.CounterName, Table2.Chartline
HAVING (((Table2.Chartline)=1000));

qry4 - crosstab query to pivot the row values to columns so we can do math on side by side values
Code:
TRANSFORM Avg(Query3.SumOfBalance) AS [Total Of SumOfBalance]
SELECT Query3.Counter, Query3.CounterName FROM Query3
GROUP BY Query3.Counter, Query3.CounterName
PIVOT Query3.Month;

qry5 - do the math
Code:
SELECT Query4.Counter, Query4.CounterName, Query4.[3], Query4.[6], [6]-[3] AS Inc_Dec FROM Query4;

I didn not try to name the column Inc(Dec) because Access will no doubt interpret that as a UDF (user defined function). Your grand total row is a job for a form or report. Access is not Excel, after all!
Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top