# IFF function with Multi Criteria

jeannie Jones used Ask the Experts™
on
Im trying to create a nested IFF function to turn this excel function in access. The basic excel formula is =IFERROR(SUM(COUNTIFS('Import Report'!E:E,{"CM","MMNRO","MMROI","PMCM","PMINS","PMOR","PMPDM","PMREG","PMRT"},'Import Report'!K:K,">="&(A2-1/24),'Import Report'!K:K,"<"&(C2+23/24),'Import Report'!F:F,"*COMP*",'Import Report'!O:O,">="&(A2-1/24),'Import Report'!O:O,"<"&(C2+23/24),'Import Report'!X:X,"LEWMXTCHE"))/SUM(COUNTIFS('Import Report'!E:E,{"CM","MMNRO","MMROI","PMCM","PMINS","PMOR","PMPDM","PMREG","PMRT"},'Import Report'!K:K,">="&(A2-1/24),'Import Report'!K:K,"<"&(C2+23/24),'Import Report'!X:X,"LEWMXTCHE")),0)
Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Analyst Assistant

Commented:
Can you explain, in words, what that 'basic' Excel formula is meant to do?:)

Also, in Access which fields would correspond to the Excel columns being used in the formula?
Database Developer

Commented:
my access table fields are as follows:
2018-09-18_13-13-39.jpg
Database Developer

Commented:
the formula that i have written on paper is this.
status (COMP or FCOM) and ActualLaborhours(>0) and ActualStart date ( what ever dates the user puts in on the form{startDate and EndDate  [divided By\]

WorkType(PMINS,PMOR,PMPDM,PMREG,PMRT) and Status( not = CAN) And TargetStartDate(what ever dates the user puts in on the form{startDate and EndDate )
Distinguished Expert 2017
Commented:
When you have compound conditions, you must repeat the field name so:

IIf((Status = "COMP" OR Status = "FCOM") AND (ActualLaborHours >0 And ActualStartDate Between Forms!yourform!StartDate And Forms!yourform!EndDate), SomeField / Nz(SomeOtherField, IIf(.... next If, true action, false action)  As CalcResult

Your explanation is fuzzy so I'm not going to try to build the rest of the IIf()

Just remember 2 things:
1. repeat the column name if you want to compare to multiple values
2. Enclose the parts of the criteria in parentheses to ensure that the expression is evaluated as you intend.

Access follows standard order of operation rules.

a and b or c or d  is evaluated as (a and b) or c or d

whereas you probably want  a and (b or c or d)
Retired IT Professional

Commented:
Upload the excel worksheet with few rows of data.
Database Developer

Commented:
i have uploaded  some sample data that is in my excel sheet
testdata.xlsx
Retired IT Professional

Commented:
``````Im trying to create a nested IFF function to turn this excel function in access
``````

Fill the first row of the sheet with names for headings  as in the access table.
I assume you want to transfer the excel sheet to access table.

Also upload a demo of any database related to the issue.
Database Developer

Commented:
can you show me a rough draft of what this would look like in access Query designer please
Retired IT Professional

Commented:
To be able to do that, one should understand the problem.
My previous request will make it easy for me to help.
Distinguished Expert 2017

Commented:
I showed you how it would look in  a query:

Select .... my sample, ....
Retired IT Professional

Commented:
look like in access Query designer
1. Name first row in excel with suitable column names.
2. Get external data from Excel, and link to specified excel sheet.
3. Open query designer and use the linked table as record source.
4. Select related fields to create the select statement.
Database Developer

Commented:
I did that already and its not coming up with the right number that is on the excel sheet.
Retired IT Professional

Commented:
I did that already and its not coming up with the right number that is on the excel sheet.

The question will bloat if we keep uncovering new information after few comments.

So speed up the solution to the issue, upload what you have done, in access and excel, to investigate.
Try that with a spreadsheet with few (3-5) columns.
Database Developer

Commented:
SELECT Count(*) AS LEW
FROM MaximoReportT
WHERE (((MaximoReportT.Status)="COMP") AND ((MaximoReportT.ActualLaborHours)>"00:00") AND ((MaximoReportT.ActualStartDate) Between [Enter the Start Date] And [Enter the End Date])) OR (((MaximoReportT.Status)="FCOMP"));

UNION SELECT Count(*) AS LEW
FROM MaximoReportT
WHERE ((WorkType) In ("PMINS","PMOR","PMPDM","PMREG","PMRT")) AND ((Status)<>"CAN") AND (TargetStartDate) Between [Enter the Start Date] And [Enter the End Date];

Here the query i got so far and it returns a value off 133/608  now i need to get those numbers into a percentage. i have attached the database it self
MaximoAnylyzer11--Edit-.accdb
Retired IT Professional

Commented:
It has many objects.
I ran union query UnionPMCOMPQ, and got:
LEW
0
1950

so what shall I look for and what to expect,
Database Developer

Commented:
run the query that says Union
Database Developer

Commented:
and now i trying to figure out from the union query how i can get it to calculate the percentage between those numbers
Retired IT Professional

Commented:
I did.
What is the expected result?

Upload the excel sheet. Make sure the column titles are the same as the excel table.
Database Developer

Commented:
all I am trying do Is get this in access to have the same calculations as the dash sheet in excel
DASH-Details---Simple.xlsm
Retired IT Professional

Commented:
Thanks!
I was expecting to narrow down the scope.

Anyway I'll give it a try sometime later.

In the mean time other experts may join in.

Do more with