How to Count Columns until the Value is Reached in Excel – 2 Steps

The dataset showcases Sales Person , Target and units sold in Quarter-1.

To calculate how many months they took to achieve their Target:

excel count columns until value reached


Use the IFERROR, MATCH, SUBTOTAL, OFFSET, COLUMN, and MIN functions .

Step 1 – Applying a Combined Formula in the Output Cell

  • Go to G5 and enter the formula.
=IFERROR(MATCH(TRUE,SUBTOTAL(9,OFFSET(D5,,,,COLUMN(D5:F5)-COLUMN(D5)+1))>=C5,0)-MIN(IF(D5:F5<>"",COLUMN(D5:F5)-COLUMN(D5)+1))+1,"Target Not Fulfilled")

As you enter the SUBTOTAL, you will see a list of function numbers. Choose 9 (to sum the numbers).

excel count columns until value reached

Formula Breakdown:

  • COLUMN(D5) —> returns the column number of D5
    • Output: {4}
  • COLUMN(D5:F5) —>  returns the column number of D5:F5
    • Output: {4}, {5}, {6}
  • IF(D5:F5<>””,COLUMN(D5:F5)-COLUMN(D5)+1) —> returns the output of the logical statement.
    • IF({TRUE,TRUE,TRUE},{4}, {5}, {6}-{4}+1)
      • Output: {1,2,3}
  • MIN(IF(D5:F5<>””,COLUMN(D5:F5)-COLUMN(D5)+1)) —> determines the minimum value.
    • MIN({1,2,3})
      • Output: {1}
  • OFFSET(D5,,,,COLUMN(D5:F5)-COLUMN(D5)+1) —> returns a reference to a range with specific height and width calculated by row down and column right.
    • OFFSET(250,,,,{4}, {5}, {6}-{4}+1)
      • Output: {250,250,250}
  • SUBTOTAL(9,OFFSET(D5,,,,COLUMN(D5:F5)-COLUMN(D5)+1))>=C5 —> returns the subtotal. Here, it will sum, as the function_num is 9.
    • SUBTOTAL(9,{250,250,250})>=C5
      • Output: {FALSE,TRUE,TRUE}
  • MATCH(TRUE,SUBTOTAL(9,OFFSET(D5,,,,COLUMN(D5:F5)-COLUMN(D5)+1))>=C5,0)-MIN(IF(D5:F5<>””,COLUMN(D5:F5)-COLUMN(D5)+1))+1 —> returns the relative position of an item that matches a specific value.
    • MATCH(TRUE, {FALSE,TRUE,TRUE},0-{1})+1
      • Output: {2}
  • IFERROR(MATCH(TRUE,SUBTOTAL(9,OFFSET(D5,,,,COLUMN(D5:F5)-COLUMN(D5)+1))>=C5,0)-MIN(IF(D5:F5<>””,COLUMN(D5:F5)-COLUMN(D5)+1))+ 1,”Target Not Fulfilled”) —> finds whether the output is valid. If it isn’t, it will return “Target Not Fulfilled”
    • =IFERROR({2}”Target Not Fulfilled”)
      • Output: {2}
  • Press ENTER.

This is the output.


Step 2 – Use the AutoFill Feature to Get the Count of Rows in the Table

  • Drag down the Fill Handle to AutoFill the rest of the cells.

excel count columns until value reached

This formula calculates the Months Required to achieve the Target for each salespersonAlex: 2 months.


Practice Workbook

Practice here.

 


Download Workbook


 

<< Go Back to Count Columns | Formula List | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Akib Bin Rashid
Akib Bin Rashid

AKIB BIN RASHID, a materials and metallurgical engineer, is passionate about delving into Excel and VBA programming. To him, programming is a valuable time-saving tool for managing data, files, and internet-related tasks. Proficient in MS Office, AutoCAD, Excel, and VBA, he goes beyond the fundamentals. Holding a B.Sc in Materials and Metallurgical Engineering from Bangladesh University of Engineering and Technology, MD AKIB has transitioned into a content development role. Specializing in creating technical content centred around Excel and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo