简体   繁体   中英

Sumif Excel Function Error

I'm trying to calculate the days that an employee had an overtime; but the function keeps give an error function. I tried after searching use (;) instead of (,); but still keep getting the error.

The function:

=SUMIFS(LeaveTracker[Days],LeaveTracker[Employee Name],valSelEmployee,WEEKDAY(LeaveTracker[Start Date]),">5",WEEKDAY(LeaveTracker[End Date]),">5",LeaveTracker[Type of Leave],'Leave Types'!B8)

The Error message: The formula you typed contains an error.

As I wrote in my comment, criteria_range arguments need to be ranges. You have two which are not: WEEKDAY(LeaveTracker[Start Date]) and WEEKDAY(LeaveTracker[End Date]) do not return a range. They returns an array of weekday numbers. Hence your error.

You could add two helper columns containing just the Weekday number referenced to start and end date, and then use those columns for the criteria_range in place of what you have.

So add a column named StartWeekDay with the formula: =WEEKDAY([@[Start Date]]) and similarly add a column named EndWeekDay

Then you can use SUMIFS :

=SUMIFS(LeaveTracker[Days],LeaveTracker[Employee Name],valSelEmployee,(LeaveTracker[StartWeekDay]),">5",(LeaveTracker[EndWeekDay]),">5",LeaveTracker[Type of Leave],'Leave Types'!B8)

Or you can use the SUMPRODUCT function, which can perform that logic on your existing data with no need for helper columns.

=SUMPRODUCT(LeaveTracker[Days]*(LeaveTracker[Employee Name]=valSelEmployee)*(WEEKDAY(LeaveTracker[Start Date])>5)*(WEEKDAY(LeaveTracker[End Date])>5)*(LeaveTracker[Type of Leave]='Leave Types'!B8))

The syntax for SUMIFS is :

SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)

If:

LeaveTracker[Days] is the sum_range and

LeaveTracker[Employee Name] is the criteria_range

what is valSelEmployee?

According to the syntax, it should be the first criteria. Does it contain the Employee name to search? If so, it should have an operator (=, > etc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM