I have the following Query:
I want the QTotal to show the total of the Q1 to Q4 fields but it comes up blank.
I have tried:
Qtotal: Nz([Q1])+Nz([Q2])+Nz([Q3])+Nz([Q4])
but this throws and exepction the first time the query is run and then it works.
Any thoughts?
You need to re-write that query using IIf(IsNull... instead of Nz(... Pretty sure there are some incompatibility issues with the Nz function.
Related
I am trying to understand expression in QV for the past few days and am unable to follow what it is trying to do especially the aggregate part with a nodistinct sum.
I've tried to understand how aggregate works and how nodistinct with sum but am not able to connect with the rest of the expression.
sum([INFLUENCE ON SALE]
* aggr(NODISTINCT SUM({<PART_NUMBER, [INFLUENCE ON SALE],[Campaign
Name],ROOTCAUSE=>}[TOTAL OCCATIONS 12]),KEY,YEAR)
/aggr(NODISTINCT SUM({<PART_NUMBER, [INFLUENCE ON SALE],[Campaign
Name],ROOTCAUSE=>}[TOTAL OCCATIONS 12]),YEAR))
WHAT is this expression trying to do with the aggregate and nodistinct part. can this be simplified and explained with a simple example?
you have to show the chart (table) in order to understand the use of nodistinct in this specific calculation. nodistinct "spreads" the results across dimensions even though the dimension is not in the aggr function...
I have a column which should calculate some numbers and sometimes it gives me the correct sum and sometimes it doesn't. I don't know why! Can someone please point me in the right direction?
I used this expression:
=Sum(Fields!TotalEmployees.Value)
When I don't choose something from filters on the top , it will give me the correct sum:
And when I choose something from the filters on the top, for example between 2 dates, it will give me wrong the sum:
Parameters & Body of report :
#EndDateFrom
#EndDateTo
Yeah, you need to be wary of your grouping. I'm willing to bet you're stuck inside of a group which is filtering your results.
If you are using Report Builder 2016, you can right click your last row and select "Add Total". This will generally automatically generate a row that gets the sum of all fields in your group.
i solved this issue with changing my query ,where all calculating (AVG , Sum &.. ) happens in query , instead reporting services do it for me .. after that i got the correct number:
SELECT t1.Departments, count(t1.id), avg(t1.age),sum(t1.TotalEmployees)/count(t1.id)
AS TotalEmpl FROM (<current_query>) AS t1 <br> GROUP BY t1.Departments
I'm trying to make a query using a calculation with Date().
I have a field named [Currentordue] and a field named [duedate]. What I'm trying to accomplish is making a query to limit the results by "if [currentordue] equals "due" or if [duedate] minus today's date is less than 30 days."
I've tried a few different ways but always seem to end with either an error or with no results showing (which would be an error as well since I know there are fields that are due).
Any and all help would be appreciated.
Here is a way to use two different date conditions:
SELECT Table1.Currentordue, Table1.duedate, DateDiff("d",[duedate],Date()) AS Expr1
FROM Table1
WHERE (((DateDiff("d",[duedate],Date()))<30)) OR (((Table1.Currentordue)=[duedate]));
I'm trying to build a query (QueryB) for it to be referenced in my MS Access control. I know I got the source expression syntax right, I have a very similar working control with QueryA.
I only changed the field and query names. However I keep getting the infamous #Name? error with QueryB. The difference between QueryA and QueryB is the SQL code. QueryA has a GROUP BY and SUM() and QueryB only has DATEDIFF(). I have tried adding the GROUP BY to QueryB, but kept getting [...execute query does not include the specified expression as part of aggregate function].
Query B:
SELECT IIF(DATEDIFF("d",Date_X,Date_Y)>100),
ROUND(IIF(DATEDIFF("d",Date_X,Date_Y)/30,2),
DATEDIFF("d",Date_X,Date_Y)
AS DATEDIFF_X_Y
FROM LAB_DATES GROUP BY LAB_DATES.ID;
This is in MS Access SQL.
ControlB source referencing QueryB in MS Access:
=DLookUp("[DATE_DIFF_X_Y]",
"[QueryB]",
"[LAB_DATES.ID] = " & [Forms]![Lab Results Form]![Textbox_DATE_ID])
When taking out the GROUP BY, this query runs fine but I get the #Name? error in the control. All data is from ODBC MySQL. Access is the front end.
Edit: I can just drop GROUP BY. But I will get the #Name? error. My goal is to display the date difference between Date_X and Date_Y.
[...execute query does not include the specified expression as part
of aggregate function]
That error message already indicates that using GROUP BY does not work with aggregate Functions.
DATEDIFF() is an aggregate function and does not work with a GROUP BY.
The reason for that is that GROUP BY reduces your dataresult and only displays one line per different entry of the column you are using.
What is your aim for that query anyways? I am sure there is a different solumtion for that problem. GROUP BY DATE.ID sounds like you are making a GROUP BY on the primary key which has no effect, because primary keys are unique per definition.
I think your problem is within your DLookup rather than your query. You do not need the GROUP BY at all, this will cause the query to error, you can simply make QueryB:
SELECT IIF(DATEDIFF("d",Date_X,Date_Y)>100),
ROUND(IIF(DATEDIFF("d",Date_X,Date_Y)/30,2),
DATEDIFF("d",Date_X,Date_Y) AS DATEDIFF_X_Y
FROM LAB_DATES;
The problem is that in your DLookup you are using:
[LAB_DATES.ID]
Where you actually want
[LAB_DATES].[ID]
i.e. In it's current form you are looking for a column called LAB_DATES.ID rather than a Column called ID in the object LAB_DATES. Changing your DLookup to this:
=DLookUp("[DATE_DIFF_X_Y]",
"[QueryB]",
"[LAB_DATES].[ID] = " & [Forms]![Lab Results Form]![Textbox_DATE_ID])
Should do the trick.
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.