Countifs

%3CLINGO-SUB%20id%3D%22lingo-sub-2661758%22%20slang%3D%22en-US%22%3ECountifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2661758%22%20slang%3D%22en-US%22%3EIn%20the%20sheet%20there%20r%2010%20sales%20managers%20and%20they%20have%2015%20agents.%20Agents%20have%20done%20business%20whose%20amounts%20are%20mentioned.%20Question%20is-%20Need%20SM%20wise%2C%20how%20many%20agents%20have%20done%20business%20over%2025k%20till%20date.%20What%20shld%20be%20the%20countifs%20formula%3F%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2661758%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2662156%22%20slang%3D%22en-US%22%3ERe%3A%20Countifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2662156%22%20slang%3D%22en-US%22%3EThis%20would%20probably%20best%20be%20done%20in%20a%20pivot%20table.%20If%20you%20take%20the%20data%2C%20turn%20it%20into%20a%20pivot%20and%20use%20agents%20as%20row%20field%20and%20sales%20%24's%20as%20values%2C%20it'll%20list%20each%20agent%20and%20their%20total%20sales.%20Then%20you%20can%20right%20click%20the%20sales%20totals%20%26gt%3B%20sort%20by%20largest%20to%20smallest%20and%20easily%20see%20who%20did%20over%2025k.%3CBR%20%2F%3E%3CBR%20%2F%3EMore%20info%20on%20your%20data%20and%20workbook%20would%20be%20helpful!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2662766%22%20slang%3D%22en-US%22%3ERe%3A%20Countifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2662766%22%20slang%3D%22en-US%22%3EThis%20is%20gnarly%2C%20but%20isn't%20it%20basically%20just%20rebuilding%20a%20pivot%20table%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2665726%22%20slang%3D%22en-US%22%3ERe%3A%20Countifs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2665726%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F993615%22%20target%3D%22_blank%22%3E%40DKoontz%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20don't%20think%20so.%26nbsp%3B%20The%20SUMIFS%20function%20with%20arrays%20for%20the%20criteria%20fields%20can%20replicate%20the%20values%20one%20would%20obtain%20with%20a%20pivot%20table%2C%20but%20I%20don't%20think%20the%20calculation%20is%20executed%20by%20the%20same%20code.%26nbsp%3B%20Since%20I%20use%20Excel%20365%20Insider%20beta%20channel%2C%20I%20have%20access%20to%20new%20functions%20that%20allow%20solutions%20to%20depart%20even%20further%20from%20the%20norms%20of%20traditional%20spreadsheet.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel-formula%22%3E%3CCODE%3E%3D%20MAP(UNIQUE(SalesManager)%2C%0A%20%20%20%20%20%20LAMBDA(mgr%2C%0A%20%20%20%20%20%20%20%20%20LET(%0A%20%20%20%20%20%20%20%20%20%20%20%20teamMember%2C%20%20%20%20%20%20UNIQUE(FILTER(SalesPerson%2C%20SalesManager%3Dmgr))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20teamSalesAmount%2C%20SUMIFS(SalesAmount%2C%20SalesPerson%2C%20teamMember)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20SUM(SIGN(teamSalesAmount%20%26gt%3B%20Threshold))%0A%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20)%0A%20%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThat%20is%3A%3C%2FP%3E%3CP%3E-%20for%20each%20distinct%20sales%20manager%2C%26nbsp%3B%20filter%20the%20sales%20person%20list%20to%20return%20the%20managers%20team%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E-%20for%20each%20team%20member%2C%20calculate%20their%20total%20sales%20to%20date%3B%3C%2FP%3E%3CP%3E-%20count%20the%20number%20that%20exceed%20the%20cut-off%20value.%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20greatest%20challenge%20might%20be%20even%20recognising%20that%20the%20offered%20solution%20is%20an%20Excel%20worksheet%20formula!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor
In the sheet there r 10 sales managers and they have 15 agents. Agents have done business whose amounts are mentioned. Question is- Need SM wise, how many agents have done business over 25k till date. What shld be the countifs formula?
9 Replies
This would probably best be done in a pivot table. If you take the data, turn it into a pivot and use agents as row field and sales $'s as values, it'll list each agent and their total sales. Then you can right click the sales totals > sort by largest to smallest and easily see who did over 25k.

More info on your data and workbook would be helpful!

@Chirantan_77 

This only applies to Excel 365.

= LET(
  distinctSalesManager, UNIQUE(SalesManager),
  distinctSalesPerson,  UNIQUE(SalesPerson),
  totalSales, SUMIFS(SalesAmount, SalesPerson, distinctSalesPerson),
  qualifies,  SIGN(totalSales>=Threshold),
  personsManager, XLOOKUP(distinctSalesPerson, SalesPerson, SalesManager),
  matrix, SIGN(TRANSPOSE(personsManager) = distinctSalesManager),
  CHOOSE({1,2}, distinctSalesManager, MMULT(matrix, qualifies)))

It calculates the total sales for each sales person, then build a matrix to show which sales manager the sales person reports to.  Matrix multiplication is then used to count the number of salesmen managed by the given sales manager have met the threshold sales value.

This is gnarly, but isn't it basically just rebuilding a pivot table?

@DKoontz 

PivotTable requires refresh, from that point of view formulas is always better. But if go this way

- load by Power Query named cell Threshold to data model;

- creating PivotTable add data to data model;

- couple of measures

sumAmount:=SUM ( Range[Sales Amount] )

Top Staff:=SUMX (
    VALUES ( Range[Sales Person] ),
    INT ( [sumAmount] > VALUES ( Threshold[Column1] ) )
)

second one into PivotTable:

image.png

@DKoontz 

I don't think so.  The SUMIFS function with arrays for the criteria fields can replicate the values one would obtain with a pivot table, but I don't think the calculation is executed by the same code.  Since I use Excel 365 Insider beta channel, I have access to new functions that allow solutions to depart even further from the norms of traditional spreadsheet.

= MAP(UNIQUE(SalesManager),
      LAMBDA(mgr,
         LET(
            teamMember,      UNIQUE(FILTER(SalesPerson, SalesManager=mgr)),
            teamSalesAmount, SUMIFS(SalesAmount, SalesPerson, teamMember),
            SUM(SIGN(teamSalesAmount > Threshold))
         )
      )
   )

That is:

- for each distinct sales manager,  filter the sales person list to return the managers team;  

- for each team member, calculate their total sales to date;

- count the number that exceed the cut-off value. 

The greatest challenge might be even recognising that the offered solution is an Excel worksheet formula!

 

@Peter Bartholomew 

Never think about that, but logic behind is close (yes, sure, that's not the mapping)

 

- MAP() creates rows content as if in PivotTable we put SalesManager into rows;

- SUM([Sales Amount] in current content works as SUMIFS()

- VALUES([Sales Person]) is UNIQUE(SalesPerson) for current row content;

- SUMX() iterates it (again, for current content) and sums number of condition met.

@Peter Bartholomew 

This is seriously so cool, way beyond my current scope, I don't have MAP or LAMBDA access with my current subscription. Where did you guys (@Sergei Baklan too) learn this stuff? I'm always trying to get better with excel and you've blown my mind with building these custom functions and matrixes.

 

Totally next level stuff.

@DKoontz 

Lambdas are available for Office Insiders with 365 subscription on Beta and now Current (Preview) channels.

Supporting functions like MAP() are only on Beta channel.

Brief description is in blogs here in Excel community, plus on Office Insider site in blogs, plus support pages (e.g. google "excel lambda scan"), plus on different forums includes this one.

@DKoontz 

The primary source of information is the blog announcements (as an MVP @Sergei Baklan presumably gets more in the way of previews).

Basic arrays:

Microsoft Excel: Advanced spreadsheet modeling usi... - Power Platform Community

The LET function:

Announcing LET in Excel (microsoft.com)

The LAMBDA function:

Announcing LAMBDA (microsoft.com)

LAMBDA helper functions (these make recursive calculation more straightforward)

Announcing LAMBDA Helper Functions (microsoft.com)

The next thing is to gain access to an Excel 365 license that you have the authority to switch to the Insider beta channel and then start practicing and developing new techniques.