I can't figure out it what's the problem

Shafique

Board Regular
Joined
Nov 23, 2018
Messages
119
in a query i am trying to sum a numeric field value based two fields value combination criteria
before that i it working very well but with one field value
please tell me what is the right expression
 

Attachments

  • error.jpg
    error.jpg
    71.7 KB · Views: 10

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
You are missing the "&" before that highlighted word.
 
Upvote 0
last time i used
BALANCE: DSum("PAPERPRD","IMPPRD","REELCOLOR='" & [REELcolor] & "'")
it works very well. i just want to add another criteria [REELGSM]
I want the sum of PAPERPRD where the REELCOLOR and REELGSM matched
as i add REELGSM the query result is blank
 
Upvote 0
You need to understand something when building these expressions.
There are two different pieces when constructing a dynamic expression:
- literal text, which is surrounded by double-quotes
- field references, which are outside of double-quotes

When combining these pieces together, you do so with a & in between each piece.
 
Upvote 0
as i add "&" the query result has been blank
Please post the exact expression you are now using for the DSUM that is returning nothing.

Quite frankly, I would recommend against using DSUM, if possible. Most of the time, an Aggregate Query would work better.
 
Upvote 0
Please post the exact expression you are now using for the DSUM that is returning nothing.

Quite frankly, I would recommend against using DSUM, if possible. Most of the time, an Aggregate Query would work better.
as you guide me before
You are missing the "&" before that highlighted word.
i add it in my expression

BALANCE: DSum("PAPERPRD","IMPPRD","REELCOLOR=" & [REELCOLOR] & " AND " & [REELGSM]=" & [REELGSM] &")
 
Upvote 0
OK, you also have an extra & and " at the end of your statement and a misplaced one too.
Try:
VBA Code:
BALANCE: DSum("PAPERPRD","IMPPRD","REELCOLOR=" & [REELCOLOR] & " AND [REELGSM]=" & [REELGSM])

However, there may be more to it than that, depending on your data type.
You are using two fields in this formula: REELCOLOR and REELGSM. What data types are these?
If they are string/text, they will need to be surrounded by single quotes.

Also, it seems very odd to me that your field names and variables have the exact same names (i.e. "REELCOLOR and [REELCOLOR]).
Are you sure that is correct?
Where do these values that you are plugging into this formula coming from?
 
Upvote 0
OK, you also have an extra & and " at the end of your statement and a misplaced one too.
Try:
VBA Code:
BALANCE: DSum("PAPERPRD","IMPPRD","REELCOLOR=" & [REELCOLOR] & " AND [REELGSM]=" & [REELGSM])

However, there may be more to it than that, depending on your data type.
You are using two fields in this formula: REELCOLOR and REELGSM. What data types are these?
If they are string/text, they will need to be surrounded by single quotes.

Also, it seems very odd to me that your field names and variables have the exact same names (i.e. "REELCOLOR and [REELCOLOR]).
Are you sure that is correct?
Where do these values that you are plugging into this formula coming from?
the both fields [REELCOLOR] AND [REELGSM] contains numeric type data. but in table i set these fields Data Type as Short Text
REELCOLOR means = 8835
REELGSM means = 60

i tried the expression that you sent to me but it returns with this error [ATTACHED]
 

Attachments

  • table.jpg
    table.jpg
    50.2 KB · Views: 10
  • error.jpg
    error.jpg
    74.6 KB · Views: 8
Upvote 0
If they are truly text fields, then the values need to be enclosed in single quotes like this:
VBA Code:
BALANCE: DSum("PAPERPRD","IMPPRD","REELCOLOR='" & [REELCOLOR] & "' AND [REELGSM]='" & [REELGSM] & "'")

Also, since this is a calculated field, I don't think you want to select the "Group By" option on the "Total" row for this field.
I think you want the "Expression" option.
 
Upvote 0

Forum statistics

Threads
1,216,089
Messages
6,128,750
Members
449,466
Latest member
Peter Juhnke

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