Home

Need help with a formula in excel

%3CLINGO-SUB%20id%3D%22lingo-sub-753746%22%20slang%3D%22en-US%22%3ENeed%20help%20with%20a%20formula%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-753746%22%20slang%3D%22en-US%22%3E%3CP%3EGreetings%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20help%20writing%20a%20formula.%20Attached%20is%20a%20screen%20shot%20of%20my%20data%20in%20excel.%20What%20I%20am%20trying%20to%20accomplish%20is%20to%20have%20excel%20return%20the%20number%20of%20times%20a%20specific%20code%20occurs%20under%20each%20area.%20Example%2C%20for%20area%20%231%20Saw%2C%20the%20code%20%22electrical%22%20occurs%202%20times.%20I%20know%20I%20could%20use%20a%20COUNTIF%20formula%3B%20however%20when%20I%20do%20this%20is%2C%20it%20is%20not%20very%20quick%20and%20doesn't%20work%20when%20I%20drag%20down%20to%20get%20the%20rest%20of%20the%20data.%20Any%20ideas%20of%20formulas%20that%20would%20work%20quickly%20for%20my%20data%20set%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-753746%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-753775%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20a%20formula%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-753775%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F375964%22%20target%3D%22_blank%22%3E%40laport14%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%3C%2FP%3E%3CP%3EAlthough%20I%20cannot%20clearly%20see%20the%20column%20headings%20in%20your%20screenshot%20but%20assuming%20that%20your%20first%20condition%20is%20in%20Column%20A%20(Starting%20from%20A2%20to%20A500%3C%2FP%3E%3CP%3Eand%20your%20second%20criteria%20range%20is%20in%20Column%20F%20starting%20from%20F2%20to%20F500'%3C%2FP%3E%3CP%3EThen%3C%2FP%3E%3CP%3EYou%20want%20to%20count%20based%20upon%202%20conditions%20%3A%3C%2FP%3E%3CP%3EOptions%20for%20Condition%201%20are%20set%20in%20Column%20J%20starting%20from%20J6%3C%2FP%3E%3CP%3EOptions%20for%20condition%202%20is%20in%20Cell%20K5%3C%2FP%3E%3CP%3EThen%20in%20Cell%20K6%20I%20will%20create%20a%20SUMPRODUCT%20function%20as%20follows%3A%3C%2FP%3E%3CP%3E%3DSUMPRODUCT((%24A%242%3A%24A%24500%3D%24K%245)*(%24F%242%3A%24F%24500%3D%24J%246))%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F123244i76D10C3AA727FC6A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SumProduct.png%22%20title%3D%22SumProduct.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EHope%20that%20helps%3C%2FP%3E%3CP%3ENabil%20Mourad%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-753786%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20a%20formula%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-753786%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F375964%22%20target%3D%22_blank%22%3E%40laport14%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20wish%20you%20had%20posted%20some%20sample%20data%20along%20with%20the%20formulas%20you%20are%20complaining%20about%20rather%20than%20a%20screenshot.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20said%2C%20you%20have%20posted%20a%20problem%20that%20is%20well-suited%20for%20solution%20using%20a%20PivotTable.%20PivotTables%20only%20calculate%20when%20you%20rightclick%20and%20choose%20Refresh.%20So%20they%20are%20much%20less%20calculation%20intensive.%20If%20you%20insist%20on%20using%20formulas%2C%20since%20you%20are%20wanting%20to%20count%20the%20number%20of%20incidents%20for%20each%20combination%20of%20Code%20and%20Area%2C%20you%20will%20need%20COUNTIFS%20formulas%20rather%20than%20COUNTIF.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20first%20step%20in%20creating%20a%20PivotTable%20is%20to%20move%20your%20existing%20data%20into%20a%20Table.%20You%20can%20do%20this%20by%20clicking%20any%20cell%2C%20then%20using%20the%20Insert...Table%20menu%20item.%20Make%20sure%20to%20check%20the%20box%20for%20My%20data%20has%20headers.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20might%20want%20to%20calculate%20the%20lost%20time%20for%20each%20combination%20of%20Code%20and%20Area%2C%20you%20should%20add%20a%20column%20to%20your%20table%20with%20a%20formula%20calculating%20the%20lost%20time%20for%20that%20row.%20A%20PivotTable%20can%20sum%20up%20the%20lost%20time%20as%20well%20as%20count%20the%20number%20of%20incidents.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20build%20the%20PivotTable%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ESelect%20any%20cell%20in%20the%20Table%20containing%20your%20data%3C%2FLI%3E%0A%3CLI%3EUse%20the%20Insert...PivotTable%20menu%20item%3C%2FLI%3E%0A%3CLI%3EThe%20default%20is%20to%20put%20the%20PivotTable%20on%20a%20newly%20inserted%20worksheet%2C%20but%20I%20prefer%20to%20put%20it%20on%20the%20same%20worksheet%20as%20my%20data%3C%2FLI%3E%0A%3CLI%3EYou%20will%20now%20be%20confronted%20with%20an%20unfamiliar%20task%20pane.%20Take%20a%20deep%20breath%2C%20then%20drag%20Code%20into%20Row%20items%2C%20Area%20into%20Column%20items%2C%20and%20Area%20into%20Value%20items.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-754009%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20a%20formula%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-754009%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F375964%22%20target%3D%22_blank%22%3E%40laport14%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%3C%2FP%3E%3CP%3EAlthough%20in%20my%20reply%20I%20was%20sticking%20to%20your%20original%20setup%2C%20however%20I%20agree%20with%26nbsp%3B%40%3C%2FP%3E%3CDIV%20class%3D%22user-login%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F374823%22%20target%3D%22_blank%22%3EBrad_Yundt%20%3C%2FA%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3BThat%20pivot%20tables%20are%20the%20shortest%2C%20easiest%20and%20fastest%20option%20to%20achieve%20the%20desired%20outcome.%3C%2FP%3E%3CP%3EBest%20of%20luck%3C%2FP%3E%3CP%3ENabil%20Mourad%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-754014%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20a%20formula%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-754014%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F374823%22%20target%3D%22_blank%22%3E%40Brad_Yundt%3C%2FA%3E%26nbsp%3B%20Thank%20you%20for%20your%20response%2C%20here%20is%20the%20sample%20data%20set%20in%20question.%20I%20appreciate%20your%20quick%20response%20in%20reference%20to%20my%20question.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-754028%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20a%20formula%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-754028%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F375964%22%20target%3D%22_blank%22%3E%40laport14%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20you%20have%20slicers%20already%20in%20your%20workbook%2C%20I%20now%20think%20it%20better%20to%20use%20COUNTIFS%20formulas%20to%20build%20your%20report.%20They%20are%20faster%20than%20SUMPRODUCT%20and%20can%20use%20entire%20columns%20without%20causing%20delays%20in%20recalc%20time.%20With%20your%20sample%20data%2C%20they%20recalculate%20in%20the%20blink%20of%20an%20eye%20when%20I%20use%20one%20of%20the%20slicers.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20permit%20the%20slicers%20to%20affect%20the%20count%20results%2C%20I%20suggest%20adding%20a%20column%20to%20your%20Table1.%20This%20column%20will%20return%201%20if%20the%20row%20is%20visible%20or%200%20if%20not.%20I%20used%20%3DSUBTOTAL(3%2C%5B%40Area%5D)%20as%20the%20formula%20for%20this%20column.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20required%20COUNTIFS%20in%20cell%20L6%20is%20then%3A%3C%2FP%3E%0A%3CPRE%3E%3DCOUNTIFS(%24F%3A%24F%2C%24K6%2C%24A%3A%24A%2CL%245%2C%24I%3A%24I%2C1)%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-754179%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20with%20a%20formula%20in%20excel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-754179%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F375964%22%20target%3D%22_blank%22%3E%40laport14%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Euse%20the%20countifs%20formula%2C%20you%20can%20enter%20multiple%20criterias%20your%20first%20criteria%20is%20your%20column%20on%20the%20left%20part%2C%20then%20the%20second%20criteria%20is%20your%20column%20heading.%26nbsp%3B%20use%20absolute%20rows%20for%20your%20criteria%20range%20and%20your%20second%20criteria.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ecountif%20works%20just%20for%20single%20criterias%20countifs%20is%20best%20used%20for%20multiple-you%20need%20not%20enter%20complex%20ifs%20or%20array%20formulas%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Enext%20time%20include%20a%20file%20that%20can%20be%20edited%20for%20clarificatory%20details%3C%2FP%3E%3C%2FLINGO-BODY%3E
laport14
New Contributor

Greetings,

 

I need help writing a formula. Attached is a screen shot of my data in excel. What I am trying to accomplish is to have excel return the number of times a specific code occurs under each area. Example, for area #1 Saw, the code "electrical" occurs 2 times. I know I could use a COUNTIF formula; however when I do this is, it is not very quick and doesn't work when I drag down to get the rest of the data. Any ideas of formulas that would work quickly for my data set? 

 

Thank you.

6 Replies

@laport14 

Hi

Although I cannot clearly see the column headings in your screenshot but assuming that your first condition is in Column A (Starting from A2 to A500

and your second criteria range is in Column F starting from F2 to F500'

Then

You want to count based upon 2 conditions :

Options for Condition 1 are set in Column J starting from J6

Options for condition 2 is in Cell K5

Then in Cell K6 I will create a SUMPRODUCT function as follows:

=SUMPRODUCT(($A$2:$A$500=$K$5)*($F$2:$F$500=$J$6))

SumProduct.png

Hope that helps

Nabil Mourad

@laport14 

I wish you had posted some sample data along with the formulas you are complaining about rather than a screenshot.

 

That said, you have posted a problem that is well-suited for solution using a PivotTable. PivotTables only calculate when you rightclick and choose Refresh. So they are much less calculation intensive. If you insist on using formulas, since you are wanting to count the number of incidents for each combination of Code and Area, you will need COUNTIFS formulas rather than COUNTIF.

 

The first step in creating a PivotTable is to move your existing data into a Table. You can do this by clicking any cell, then using the Insert...Table menu item. Make sure to check the box for My data has headers.

 

If you might want to calculate the lost time for each combination of Code and Area, you should add a column to your table with a formula calculating the lost time for that row. A PivotTable can sum up the lost time as well as count the number of incidents.

 

To build the PivotTable:

  1. Select any cell in the Table containing your data
  2. Use the Insert...PivotTable menu item
  3. The default is to put the PivotTable on a newly inserted worksheet, but I prefer to put it on the same worksheet as my data
  4. You will now be confronted with an unfamiliar task pane. Take a deep breath, then drag Code into Row items, Area into Column items, and Area into Value items.

 

 

@laport14 

Hi

Although in my reply I was sticking to your original setup, however I agree with @

 That pivot tables are the shortest, easiest and fastest option to achieve the desired outcome.

Best of luck

Nabil Mourad

@Brad_Yundt  Thank you for your response, here is the sample data set in question. I appreciate your quick response in reference to my question.

@laport14 

Since you have slicers already in your workbook, I now think it better to use COUNTIFS formulas to build your report. They are faster than SUMPRODUCT and can use entire columns without causing delays in recalc time. With your sample data, they recalculate in the blink of an eye when I use one of the slicers.

 

To permit the slicers to affect the count results, I suggest adding a column to your Table1. This column will return 1 if the row is visible or 0 if not. I used =SUBTOTAL(3,[@Area]) as the formula for this column.

 

The required COUNTIFS in cell L6 is then:

=COUNTIFS($F:$F,$K6,$A:$A,L$5,$I:$I,1)

@laport14 

use the countifs formula, you can enter multiple criterias your first criteria is your column on the left part, then the second criteria is your column heading.  use absolute rows for your criteria range and your second criteria.

 

countif works just for single criterias countifs is best used for multiple-you need not enter complex ifs or array formulas

 

next time include a file that can be edited for clarificatory details

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies