Home > Software design >  How can I extract a total count or sum of agents who made their first sale in a specified month?
How can I extract a total count or sum of agents who made their first sale in a specified month?

Time:04-16

I am trying to extract some data out of a large table of data in Excel. The table consists of the month, the agent's name, and either a 1 if they made a sale or a 0 if they did not.

What I would like to do is plug in a Month value into one cell, then have it spit out a count of how many agents made their first sale that month.

enter image description here

Formula in column F is:

=MAX(0;COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1)-SUM(COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;IF($A$2:$A$8=E3;$B$2:$B$8))))

This is how it works (we'll use 01/03/2022 as example)

  1. COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1) This counts how many 1 there are for the proper month (in our example this part will return 2)
  2. COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;SI($A$2:$A$8=E3;$B$2:$B$8)) will count how many 1 you got in previous months of the same agents (in our example, it will return 1)
  3. Result from step 2, because it's an array formula, we sum up using SUM() (in our example, this return 1)
  4. We do result from step 1 minus result from step 3 (so we get 1)
  5. Finally, everything is inside a MAX function to avoid negative results (February would return -1 because there were no sales at all and agent B did a sale on January, so it would return -1. To avoid this, we force Excel to show biggest value between 0 and our calculation)

NOTE: Because it's an array formula, depending on your Excel version maybe you must introduce pressing CTRL ENTER SHIFT

CodePudding user response:

If one has got access to the newest functions:

enter image description here

=LET(X,UNIQUE(C3:C9),VSTACK({"Month","Total of First time sales"},HSTACK(X,BYROW(X,LAMBDA(a,SUM((C3:C9=a)*(MINIFS(C3:C9,D3:D9,D3:D9,E3:E9,1)=C3:C9)))))))
  • Related