iif statement return a blank field

Nancy2021

New Member
Joined
Dec 7, 2021
Messages
5
Office Version
  1. 2021
Platform
  1. Windows
I am using the following in a query. Instead of returning "0" when the statement is negative, I would like a blank field. Is there a way to do this? Oct: Sum(IIf(Month([uploaddate])=10,[absentdays],0))
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Welcome to the Board!

If this for an Aggregate Query?
Can you switch your query to SQL View, and copy and paste the SQL code here?
 
Upvote 0
Welcome to the Board!

If this for an Aggregate Query?
Can you switch your query to SQL View, and copy and paste the SQL code here?
Thanks for the quick reply!

SELECT Studentattendanceall.School, StudentDemographics.FirstName, StudentDemographics.LastName, Sum(IIf(Month([uploaddate])=10,[absentdays],0)) AS Oct, Sum(IIf(Month([uploaddate])=11,[absentdays],0)) AS Nov, StudentDemographics.StudentID, Studentattendanceall.NoRisk, Studentattendanceall.AtRisk, Studentattendanceall.Chronic, Studentattendanceall.PresentDays, Studentattendanceall.AbsentDays, Studentattendanceall.DaysEnrolled, Studentattendanceall.PercentAbsent, Sum(IIf(Month([uploaddate])=10,[percentabsent],0)) AS OctPercentAbsent, Sum(IIf(Month([uploaddate])=11,[percentabsent],0)) AS NovPercentAbsent, Studentattendanceall.Grade, StudentDemographics.Ethnicity, StudentDemographics.Gender, (IIf(Month([uploaddate])=11,[Chronic],"")) AS NovChronic, (IIf(Month([uploaddate])=10,[Chronic],"")) AS OctChronic
FROM StudentDemographics INNER JOIN Studentattendanceall ON StudentDemographics.StudentID = Studentattendanceall.StudentID
GROUP BY Studentattendanceall.School, StudentDemographics.FirstName, StudentDemographics.LastName, StudentDemographics.StudentID, Studentattendanceall.NoRisk, Studentattendanceall.AtRisk, Studentattendanceall.Chronic, Studentattendanceall.PresentDays, Studentattendanceall.AbsentDays, Studentattendanceall.DaysEnrolled, Studentattendanceall.PercentAbsent, Studentattendanceall.Grade, StudentDemographics.Ethnicity, StudentDemographics.Gender, (IIf(Month([uploaddate])=11,[Chronic],"")), (IIf(Month([uploaddate])=10,[Chronic],""));
 
Upvote 0
One way is to create another query based off of this query, and do something like:
Rich (BB code):
IIf([Oct]=0,"",[Oct])
However, you need to be aware of the repurcussions of replacing zeroes with blank values - those are text values and could render this field unusable if you need to perform other math operations on it.

If you are trying to hide zero values on a Report, you might be better off using Conditional Formatting to suppress those zeroes.
 
Upvote 0
AFAIK, you can't use Sum function with text or zls (zero length strings) so you would have to default to null when the test is false. Null + anything else will return Null, so I don't know if that will work for you. Perhaps try Sum(IIf(Month([uploaddate])=10,[absentdays],Null)
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top