Let's say I have two fields A and B and one textbox B_input. I would like to set up a query so it sums all entries of column A where B = B_input
Currently I have:
==Sum(IIf([B_input]<>"All",[A],IIf([B_input]<>[B],0,[A])))
I did more testing, it seem the problem is that under Sum(IIF([B_input])), it's not recognizing the value of [B_input], but if I just have IIF([B_input]), it recognize the value just fine, any ideas?
iif([B_input]=="xyz",Sum[A],False)
Might be what you're after but I'm not sure i understood your question properly.
Alternatively, just edit the sql to something like
SELECT(SUM[A]) AS SumOfA FROM [MyTable] HAVING ("B"="xyz");
How about:
=Sum(IIf([B_input]<>"All",[A],0))
Gave up, went with form filtering instead.
Related
I'd like to know if there is a way to make a field in a query dependent on a value from a text field on a form. Namely, I'd like to take a field from a table and multiply it by a value from a field on a form.
I tried Input(mg): [Percent]*[forms]![frm_Formulation]![Text4] but the field is blank when I run the query.
When I remove [forms]![frm_Formulation]![Text4] my percent field shows up as it should.
Cross post http://www.accessforums.net/showthread.php?t=68017
Suggested Edit: Here is my SQL: SELECT Tbl_Formulas.Item, Tbl_Formulas.RawMaterial, [Percent]*1257 AS [Input(mg)], Tbl_Formulas.[Quantity(kg)], Qry_Percentages.Percent
FROM Qry_Percentages INNER JOIN Tbl_Formulas ON (Qry_Percentages.Item = Tbl_Formulas.Item) AND (Qry_Percentages.[Quantity(kg)] = Tbl_Formulas.[Quantity(kg)])
WHERE (((Tbl_Formulas.Item)="a475ad"));
I tried to recreate this instance in a new database and could not. The function works. It just doesn't work in this db...
Thank you all for the responses. I figured out the problem. One of the relationships in my table were screwing with the query. Resetting the relationships solved the issue and now the function works properly. Thanks again, especially June7. You've helped me out many times now.
I have been researching on MS-Access topics around DLookup, but not being lucky on the resolution of my problem.
I have a query that solely returns one value, which is a lumpsum of credits. So I used the clause "AS TOT_CREDIT" on the query to give the unique column a name.
On access report, I learned that you can't directly set the value of a textbox from a query, but also learned the magic is to set the textbox controlsource property to dlookup, like this: dlookup([TOT_CREDIT]; [QUERY THAT CONTAINS TOT_CREDIT]). When I pull the report from access, the textbox still displays the infamous "#Name?", instead of the query value.
Is anything missing here? What else can I do in order to have the textbox display the query result?
Must use quotation marks:
DLookup("[TOT_CREDIT]"; "[QUERY THAT CONTAINS TOT_CREDIT]").
I need to create a report using SSRS, it needs dynamicly group by the matrix.
I added a parameter(name: ColumnData) for it and the available value like 'Date', 'Type', 'ServerName',
for a single value, I can edit the group by expression to
=Fields(Parameter!ColumnData.Value).Value
but when the parameter is multiple, Parameter!ColumnData.Value would return a list and I need to use like that:
==Fields(Parameter!ColumnData.Value(0)).Value & Fields(Parameter!ColumnData.Value(1)).Value
but it's not what I want as I need to indicate the index manually...
Anyone knows how to use the multiple parameters in the group by expression?
Thanks a lot!
If you deselect 'Allow multiple values' in the Parameter properties, your group by expression should work as is.
You will then be able to group by the selected value from the parameter.
(It will then not be possible to choose more than one of the values).
But it only makes sense to group on one value, or?
I stumbled on this topic, but my solution was simple. I had to group by multiply fields, and ended using something like this:
<GroupExpression>=Fields!ColumnName1.Value</GroupExpression>
<GroupExpression>=Fields!ColumnName2.Value</GroupExpression>
<GroupExpression>=Fields!ColumnName3.Value</GroupExpression>
But this may not be what you are looking for since you wanted something more generic.
You can check this answer as it has some advices about matrix:
Multiple group expressions in list (ssrs 2005)
Hope that helps.
I inserted three text boxes to test how this could work:
Text81: =1
Text82: =2
Text83: I want this one to be the sum of Text81 and Text82
Thanks in advance for your help on what I think is a pretty simple problem.
There are a couple options that spring to mind.
First you could always modify the data source for the report to include the calculated field.
Second, which is what your question drives at, you can do something like this:
=[Text81] + [Text82]
Should work when typed into the Control Source of a TextBox provided Text81 and Text82 are the data field names from the Data Source of the Report. If they are not you would put the corresponding data field names in the square brackets []
Hope this helps
My situation/problem:
TableA
id, postalcode, region
Criteria for the field i want to add value in (postalcode):
=IIf([tableA.Region]="Chicago","60064",[postalcode])
What i need to accomplish is an iif-query where:
In the field postalcode I check in the criteria if the field region equals Chicago. If so fill up the field with postalcode 60064 if not DO NOTHING
For the do nothing part I'm using the fields name, this is wrong?
am i using the criteria in the right field (the field i want to add?)
I'm using a selection query?
As you can see i'm a noob in access queries...
Can somebody give me the right iff statement?
Thx in advance,
D
I'll suggest you bracket table.Region differently, or eliminate the brackets there entirely.
=IIf([tableA].[Region]="Chicago","60064",[postalcode])
=IIf(tableA.Region="Chicago","60064",[postalcode])
If that doesn't fix the problem you're trying to solve, tell us more about the problem. If you're getting an error message, tell us what it says.
Taking a wild guess, that code as a field expression in a query will not give you an editable column in the query result set. If you want to pre-load a column value based on your criteria, but then allow the user to change the value, use a form. In the form's On Current event, load the value as you wish.
This is a dead old post but I think this was what you wanted:
=Like IIf([tableA.Region]="Chicago","60064",'*')
As far as I can understand,
if not DO NOTHING
You need to return nothing if the condition is false.
What you need is the WHERE clause instead of IIF
If I'm understanding your question correctly, you want a NULL value in Postal Code if it's not Chicago?
=IIf([tableA].[Region]="Chicago","60064","")
Please add another IIF query as OR
IIf([Forms]![Run_Macro
Form]![ReturnType_DrpDwn]="Monthly",[Forms]![Run_Macro
Form]![Cmb_Per_Ending],#1/1/2010#)
IIf([Forms]![Run_Macro Form]![ReturnType_DrpDwn]="Quarterly",#1/1/2010#,#1/1/2025#)