Excel: How to Calculate by Condition

 

Have you encountered creating a report in MS Excel in which you want to total the values but only based on a certain condition? For example you have the following worksheet:



We’re going to make a horizontal grand total of the no. of patients of the doctor on a given day(e.g. day 1); the first instinct would be to create a formula and manually add each cell like in the figure above, also totaling the amount of services per doctor on a given day the same step will have to be done. While this works, imagine we’re going to do 1 month statistic, it would be a excruciatingly tedious, not to mention error prone (if we missed a day or we’re going to insert another column in between) to do the same step. But hey, it’s a point click world and everything should be automatic(wishful thinking)  and we’re talking about Excel, programs are built on top of this, there has to be a better way.

My last resort was to manipulate it using VBA, but before that I attempted to install a Conditional Sum Wizard add-in unfortunately I didn’t have the MS Office CD. Resisting the urge to do it in VBA, I researched it not on Google but the help file and got rewarded by a not so user-friendly term called formula array.

According to the help:An array formula can perform multiple calculations and then return either a single result or multiple results. I haven’t touched with multiple result as my concern is the former, let’s modify the formula previously to


 

After entering the formula, instead of pressing the <ENTER> key, we press CTRL+SHIFT+ENTER to convert our formula into a formula array otherwise the formula will be undefined (i.e. #VALUE!.)  The formula array calculated only the values with an explicit condition (ie:only columns == “# of Patients”), simple and sweet. We didn’t have to worry about the other column being included in the calculation and even if we add another column(e.g. the 30 day stat ) we only have to modify our range and press CTRL+SHIFT+ENTER to recalculate.  And totaling the other column, involves just plain copy and paste of the formula, and change the condition. The Final Result:


Hope this proved helpful as it did for me! Smile

Published 10-17-2006 5:29 PM by bonskijr

Comments

# re: Excel: How to Calculate by Condition

Sir, Ive been doing that using Pivot Table Wizard in MS Excel. But yes it only works if you already have a table as your data source. Your example would be very useful if a user will start without a data source. Thanks. That would certainly come in handy.

Thursday, October 19, 2006 7:02 PM by darwin25

# re: Excel: How to Calculate by Condition

hi darwin,

Pivot Table? I really have to dig deeper in Excel heheh thanks for the info..

Friday, October 20, 2006 10:43 PM by bonskijr

# re: Excel: How to Calculate by Condition

hi bonski,

PivotTable is an extremely powerful tool to all auditors and accountants and power users. I have been in a manufaturing company that uses rxcel to manage all company's financials and resource planning thus implementing and integrating ERP is a mess if not hell. Users will always look at it the excel way hehe ;).

We have in a setting of just giving them the script, execute in QA, export and you will be amazed how they transform results in a complex analysis reports that would take hours/days if will be done on coding ;).

I was onces asked by an accountant, how do this ".....", I said, "sorry, in excel, I only know C1 = B1 + B2"  hehe  ;)

Sunday, October 22, 2006 6:10 PM by dehran ph