Access 2007 SQL SUM() is adding negative dollar amount in query - sql

When I'm running a query to give me a sum of the dollar amount the negative dollar amount is getting added to the total sum. However, when I just use the total sum funtion in Access it gives me the correct sum.
SELECT SUM(VstoreTotal) AS NetSales
FROM [Store Reactive Matches All Cust]
WHERE VstoreTotal>0;
Ex. $250.00
$100.00
$0.00
($100.00)
Gives me $450.00
However, when I just use the total sum funtion in Access it gives me the correct sum.
Gives me $350.00

Related

How do i sum up the values of a particular sales Rep in a table

This is the table:
How can I sum up all Expr for sales rep "03"
When I use a calculator , The sum of 03 will be correct , and I have tried sum(number-ordered * quoted_price) But it goes ahead to add all salesrep's sales together
Due to the limited amount of data, I will have to provide you with a minimal answer.
Essentially what you are doing right now is that you are trying to get a sum of all of them.
You will need to use a where condition or group by to get only data of the the rep.

How can I sum a column of $90 then $20 without removing the dollar sign in access query criteria

It gives me error that data type mismatch in criteria expression , but can sum it without removing the dollar sign
The $ sign is for display only. The values are truly numerics.
So, sum, add, or filter as for other numbers, and then apply the format, Currency, where you wish to display the totals.

IIF statement is showing a 0 where I know there is a value

I have a dataset with values that I'm am trying to put into an SSRS report. Here is some example data:
Fund#
last week amount
YTD Total
1
$100
$1500
2
$0
$300
3
$500
$500
4
$0
$0
The first column in my SSRS report is a fixed list of fund names in the certain order that I want them to appear and I want to insert the amounts from the dataset into the row with the corresponding fund name and into the right column.
I tried to get the amount for Fund 1 from last week ($100) to appear in the report using the following expression:
=iif(Fields!fund_no.Value=1,fields!last_wk_amt.Value,0)
However, this is returning a 0 value but I know it should read 100. This seems pretty simple, but I just can't figure it out what I'm doing wrong.
Thanks for the help.
It sounds like your field is an aggregate of the dataset. The IIF statement works on a ROW basis. In your expression, it finds the first row (which is apparently not 1) and returns the evaluation.
I believe it would work correctly if you SUM the IIF:
=SUM(IIF(Fields!fund_no.Value = 1, Fields!last_wk_amt.Value, 0))
If your AMT field is not a decimal value, you'd need to convert the zero to a decimal to avoid an error about aggregating mixed data types:
=SUM(IIF(Fields!fund_no.Value = 1, Fields!last_wk_amt.Value, CDEC(0)))

Powerpivot DAX - I need a way to show a value for Revenue in my profit & loss statement even if there is no Revenue

I am having an issue with a consolidated profit and loss statement using calculated fields. There is a column for GL Group, which is either Revenue or Expense. The calculated field asks "if the value of the row is Revenue then flip the sign of the number", and "if it is expense to leave it as is". And for the net income it takes the sum of both and flips the sign to give you a net profit. My issue is that if there is NO revenue then its BLANK and then expenses, which come through naturally as a positive number, remains a positive number on the net income but should rather be a negative. This is what I am looking to achieve: Revenue should be ZERO if its blank, minus expenses, the result of this will always be a negative number (remember the expenses show as positive). Looking to improve this code:
IF(HASONEVALUE(ActualsBudgetsOB[GL_GROUP]),IF(VALUES(ActualsBudgetsOB[GL_GROUP])="Revenue",CALCULATE(SUM(ActualsBudgetsOB[AMT_ACTUAL])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[FISCAL_YR]=[Max Year])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[PERIOD]<=[Max Period]))*-1,CALCULATE(SUM(ActualsBudgetsOB[AMT_ACTUAL])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[FISCAL_YR]=[Max Year])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[PERIOD]<=[Max Period]))),CALCULATE(SUM(ActualsBudgetsOB[AMT_ACTUAL])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[FISCAL_YR]=[Max Year])
,FILTER(ActualsBudgetsOB,ActualsBudgetsOB[PERIOD]<=[Max Period]))*-1)

SQL: How can I find the total and average value in one SQL statement?

I would like to calculate the total amount of expenditure and the calculate the average value from the number of rows like this:
SELECT AVG(SUM(expenditure)) from INCOME;
However, there is a error say "misuse of aggregate function sum()"
how can I achieve this?
You can't calculate the average of the total sum as there is only one total.
The average AVG() function already calculates the total as part of its logic.
This is what you want:
SELECT AVG(expenditure) as AverageExpenditure,
SUM(expenditure) as TotalExpenditure
from INCOME;
SELECT AVG(expenditure) AS avg_exp, SUM(expenditure) AS sum_exp FROM INCOME;