Domanda

I've been trying to develop a cashflow statement in access 2007. This would be so easily done in excel using formulas such as

= SUM (B6:M6) / CountIF(B6:M6)>0 

but I cant seem to wrap my head around this when it comes to access. And I need this for every company we enter data on. The cashflow statement is supposed to look like this (Since I can't yet post a pic):

----------------------------------------------------------------------------------------------------------------
Particulars | Jan | Feb | Mar | Apr | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Average |
Sales---------------------->
Salary------>
Transportation----->

and about 10 other items in the row, all with entries for Jan till Dec, however, sometimes we take 6 months worth of data and sometimes for all 12 months. (Imagine a basic excel sheet with items on the first column and headers for the next 12-13 columns).

In access, I made tables for each Item with columns as the months, eg. tblRcpt--> |rcpt_ID|Jan|Feb|... and so on till dec for all the items. Then they will be arranged and presented in an entry form which would be designed to look similar to the above table while later I would query and link them together to presentthe complete cashflow statement.

Now comes the question, I need to Average together the columns (as you can see in the right most column), BUT I only want to average together those months that have been filled (Sometimes in accounting people enter '0' where there is no data), so I cant just sum the columns and divide by twelve. It has to be dynamic, all functions seem to center around counting and averaging ROWs, not COLUMNs.

Thanks for just bearing with me and reading this, any help would be much appreciated.

È stato utile?

Soluzione

Try this

(Jan + Feb + ... + Dec) /
  ( case when Jan = 0 then 0 else 1 end
  + case when Feb = 0 then 0 else 1 end

  + case when Dec = 0 then 0 else 1 end )
as Avg

Altri suggerimenti

Your table structure should be:

Particulars | Month | Amount
Sales         1       500
Sales         2       1000
Salary        1       80000

...and so on. You can either not enter rows when you don't have a value for that month, or you can handle them in the SQL statement (as I have below):

SELECT Particulars, AVG(Amount) AverageAmount
FROM MyTable
WHERE NULLIF(Amount, 0) IS NOT NULL
GROUP BY Particulars;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top