Query - Expression not working

Moxioron

Active Member
Joined
Mar 17, 2008
Messages
436
Office Version
  1. 2019
Hello.

I think I have a relatively easy ?, but I can't figure it out.

Expr1 in the SQL below works great. However, Expr2 doesn't return anything unless the SumofRedeposit1 column has a value.

Where am I going astray? Thanks for your help.

SELECT tbl_IncomingReturns_FORMATTED.CBAcct, tbl_IncomingReturns_FORMATTED.CustomerName, tbl_IncomingReturns_FORMATTED.CustomerName2, Count(tbl_IncomingReturns_FORMATTED.Amount) AS CountOfAmount, Sum(tbl_IncomingReturns_FORMATTED.Amount) AS SumOfAmount, Sum(IIf(Left([tbl_IncomingReturns_FORMATTED].[Redeposit],2)="**",0,IIf(Left([tbl_IncomingReturns_FORMATTED].[Redeposit],1)="*",1,0))) AS CountOfRedeposit, Sum(IIf(Left([tbl_IncomingReturns_FORMATTED].[Redeposit],2)="*",[Amount])) AS SumOfRedeposit, Sum(IIf(Left([tbl_IncomingReturns_FORMATTED].[Redeposit],2)="**",1,0)) AS CountOfRedeposit1, Sum(IIf(Left([tbl_IncomingReturns_FORMATTED].[Redeposit],2)="**",[Amount])) AS SumOfRedeposit1, [CountOfAmount]-[CountOfRedeposit]-[CountOfRedeposit1] AS Expr1, [SumOfAmount]-[SumOfRedeposit]-[SumOfRedeposit1] AS Expr2
FROM tbl_IncomingReturns_FORMATTED
WHERE (((tbl_IncomingReturns_FORMATTED.Date) Between [Start Date] And [End Date]))
GROUP BY tbl_IncomingReturns_FORMATTED.CBAcct, tbl_IncomingReturns_FORMATTED.CustomerName, tbl_IncomingReturns_FORMATTED.CustomerName2
HAVING (((tbl_IncomingReturns_FORMATTED.CBAcct) Like [Chargeback Acct #] & "*"));
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I was going to suggest changing it to
Rich (BB code):
([SumOfAmount]-[SumOfRedeposit]-[SumOfRedeposit1])

and then I wasn't so sure.


!
 
Upvote 0
Fixed it!

For the Redeposit and Redeposit1 Alias I tacked on a zero at the end of the expression and wah lah.

Sum(IIf(Left([tbl_IncomingReturns_FORMATTED].[Redeposit],2)="**",[Amount],0))
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,172
Members
452,893
Latest member
denay

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