Access update query formula- Minimum date from multiple criteria - ms-access

I have created an Access update query and input the below formula in the field "Update to";
IIf(IsNull([Rule2 mapping]![MBO Hier]),"Check",IIf(IsNull([Final_Data]![Start Date]),"Check",IIf([Final_Data]![Start Date]>FixDate2(),IIf((GetReportingDate()-[Final_Data]![Start Date])>(36554),([Final_Data]![Start Date]+36555+4),IIf((GetReportingDate()-[Final_Data]![Start Date])>(36553),([Final_Data]![Start Date]+36554+4),IIf((GetReportingDate()-[Final_Data]![Start Date])>(36552),([Final_Data]![Start Date]+36553+4),IIf((GetReportingDate()-[Final_Data]![Start Date])>(3655),([Final_Data]![Start Date]+36552+4),IIf(([Final_Data]![Start Date]+3655)<[Final_Data]![Maturity Date],([Final_Data]![Start Date]+365*5+4),[Final_Data]![Maturity Date]))))),"Check")))
I would like to add a condition of minimum date as Maturity Date wherever the criteria condition is "True". Access is giving me erratic results. Please help me in adding minimum of Maturity date or [Final_Data]![Start Date]+3655xx
I tried to derive the minimum date using DMIN function but Access threw erratic results

Related

MS Access Form to Query with Date Ranges (And Even Without)

I'm new to Access and I'm building a database here at work to log all production that was done. I was able to make a query form with criteria between a date range, condition, part number and work order. Using a code in the expression builder, these are what is placed in the criterion:
Date range: Between [Forms]![Form Query]![BeginDate] And [Forms]![Form Query]![EndDate]
Part number: Like (IIf(IsNull([Forms]![Form Query]![Part Number]),"*",[Forms]![Form Query]![Part Number]))
Condition: Like (IIf(IsNull([Forms]![Form Query]![Condition]),"*",[Forms]![Form Query]![Condition]))
This is where even when part numbers and condition is empty, the query will display all records. My problem is the date range if I leave it empty (say, I simply wanted to query all of the records), it will return with zero value. I wanted it to make it simple for the user that if I leave the date range empty, it will still show all of the records. I had to temporarily put the date range as required to always return results.
Query form
Query Criteria
All input is appreciated! Thank you so much!
Provide alternate value if date is not input:
Between Nz([Forms]![Form Query]![BeginDate], #1/1/1900#) And Nz([Forms]![Form Query]![EndDate], #12/31/2200#)
For text fields, assuming value is unique and is never part of a longer string, LIKE criteria can just concatenate wildcard:
LIKE [Forms]![Form Query]![Part Number]) & "*"

Can you set a parameter that references an expression field that is calculated based on another parameter selection?

I am attempting to create a parameter which looks at the values of a field in the report which is calculated based on the entry of another parameter.
Specifically, the first parameter is a number option (30,60 or 90) and the field expression is a DATEADD that adds the parameter value to the value of a date field.
The next parameter I need is to pick dates in the "expression field" that fall into a certain range. i.e. user chooses 30 so the report generates and populates the "Hire Date" + 30.
I want to then only select the records where that new date falls into a specified range i.e. Effective Date 2/1/2020-2/29/2020. I have been looking everywhere, but cannot find an answer and I don't know if it is possible.
Results example
[EffDate Field[\]\[1\]][1]
I think this was what SuperSimmer 44 was referring to that I couldn't understand before.
I added the following parameters:
Wait - which is an integer & has set available values of 30, 60 & 90
From - Date
To - Date
I kept the field "Effective Date" in my report which was the expression =DateAdd("d",Parameters!wait.Value,Fields!HireDate.Value)
I then added a filter to the Dataset that said if the value of the expression =DateAdd("d",Parameters!wait.Value,Fields!HireDate.Value) was between #from & #to then they should include the record in the results. It worked perfectly.
Report Sample
Insert 2 parameters, one called qty to hold available values from a list 30/60/90 or 120 etc
the other called date to hold your from effective date.
Set up a calculated field in your dataset called effectivedate that utilised DateAdd, for example ie: =DateAdd("d",Parameters!qty.Value,Parameters!effectivedate.Value)
Then set a filter on your dataset that utilizes this calculated field.

Access parameter query with optional second parmeter

I have an ACCESS database that has a table with date as one of the fields. I can create a form that allows the user to enter a start date and end date and then use those in a query to filter the date for only records between those dates. But I would like to make the end date optional so if the user would only enter the start date the query would return on records greater than that date. I am trying to do this with one query and without getting into VBA but not sure if this can be done.
I tried something like this but it did not work...I got error message saying the syntax was not correct or I got no results at all.
In the date field criteria I tried
IIF(isNull([Forms]![frmdateselect]![enddate]),
(>=DateValue([Forms]![frmdateselect]![startdate])),
((>=DateValue([Forms]![frmdateselect]![startdate])) AND
(<=DateValue([Forms]![frmdateselect]![enddate]))))
Any help would be great
Have you tried replacing the IsNUll with the Nz function?
IIF(Nz([Forms]![frmdateselect]![enddate]),0),
([Forms]![frmdateselect]! [enddate]),
(>=DateValue([Forms]![frmdateselect]![startdate])),
((>=DateValue([Forms]![frmdateselect]![startdate])) AND
(<=DateValue([Forms]![frmdateselect]![enddate]))))

MS Access - Use result from query to calculate field value

I'm trying to pull some data from a query in my database into a calculated field in a table. I have dates entered for some jobs I'm recording (DateCallOpened, DateQuoteSent, DateQuoteReceived), as well as WorkType for each job to track the type of work done. I've used calculated fields to find the time it took for each record between those dates. I've also used qryTimings to find the average length of time for the WorkType.
I'd like to build fields that showed the ProjectedQuoteSent, and use the data from my query to calculate the date I can expect the quote to be sent, but I just can't figure out how to pull that data out of the query. I was hoping it would be something as simple as:
=[DateCallOpened]+[qryTimings]:[Avg Of TimeToSendQuote]
You can use a DLookup() function to grab your value from your query. So your formula would be something like:
=[DateCallOpened]+DLookup("Avg Of TimeToSendQuote", "qryTimings", _
"[WorkType]=" & [Forms]![frmMyForm]![txtWorkTypeInput])
See this for more info.

SSRS Expression with parameter in WHERE clause

In SSRS, I'm trying to calculate the average number of months a client used a program. The programID is the parameter for the whole report. I'm trying to achieve this (not written with real syntax):
=Avg(Fields!length_of_stay.Value, 0))/30.0 WHERE programid = #ProgramID
Using this question, I came up the the following code which is producing an incorrect answer. I tested in SSMS to get the actual values to compare to SSRS results.
=Avg(IIF(Fields!programid.Value = Parameters!ProgramID.Value, Fields!Length_of_Stay.Value, 0))/30.0
The "/30" is used since the value is in days and I need months. I think the issue is using the parameter value chosen; this is my first report trying to calculate expressions with parameters.
Avg returns the average of all non-null numeric values. 0 is not null so it gets included in the average, distorting your result for every row with a different PragramId. Try using Nothing instead:
=Avg(IIF(Fields!programid.Value = Parameters!ProgramID.Value, Fields!Length_of_Stay.Value, Nothing))/30.0