maxif problem and filter problem

Natit

Board Regular
Joined
Jan 22, 2012
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hello,
In the attached, I try to get the max price (cell E2) and to filter (cell A7) according to the selection of group and sub group.
While with a specific subgroup it works fine, when I select the "all" option (in B2), it doesn't work.
Can someone help me to find what is not working right in my formulas?
Thx
Nati
excel_question.xlsx
ABCDEF
1group to choosesubgroup to choosetotal priceitemsmax priceaverage
2group2subgroup26138,032.73723,928.1319,718.96
3
4
5
6cat_numdata1data2codeprice
72104data49data592280017305.95
82711data207data2172280023928.13
92732data217data2272280023928.13
102753data227data2372280023928.13
112809data245data2552280019988.83
122858data264data2742280022367.6
138038data676data686228006585.96
stats
Cell Formulas
RangeFormula
C2C2=LET( Main_unit_row,MATCH($A$2,parameters!$A$16:$A$61,0)+15, Main_next_unit_name,IFERROR(INDEX(parameters!$A$3:$F$3,MATCH($A$2,parameters!$A$3:$F$3,0)+1),""), Main_next_unit_row,MATCH(Main_next_unit_name,parameters!$A$16:$A$61,0)+15, Unit_row,MATCH($B$2,parameters!$B$17:$B$61,0)+16, Last_unit_row,SUMPRODUCT(MAX(ROW(parameters!$B:$B)*(parameters!$B:$B<>""))), Old_salary_col,Total_sheet!$E:$E, Saif_col,Total_sheet!$D:$D, All_units,IF(Main_next_unit_name="",SUM(SUMIFS(Old_salary_col,Saif_col,INDIRECT("parameters!D"&Main_unit_row+1&":O"&Last_unit_row))),SUM(SUMIFS(Old_salary_col,Saif_col,INDIRECT("parameters!D"&Main_unit_row+1&":O"&Main_next_unit_row-1)))), One_unit,SUM(SUMIFS(Old_salary_col,Saif_col,INDIRECT("parameters!D"&Unit_row&":o"&Unit_row))), IF($B$2="all",All_units,One_unit))
D2D2=LET( Main_unit_row,MATCH($A$2,parameters!$A$16:$A$61,0)+15, Main_next_unit_name,IFERROR(INDEX(parameters!$A$3:$F$3,MATCH($A$2,parameters!$A$3:$F$3,0)+1),""), Main_next_unit_row,MATCH(Main_next_unit_name,parameters!$A$16:$A$61,0)+15, Unit_row,MATCH($B$2,parameters!$B$17:$B$61,0)+16, Last_unit_row,SUMPRODUCT(MAX(ROW(parameters!$B:$B)*(parameters!$B:$B<>""))), Old_salary_col,Total_sheet!$E:$E, Saif_col,Total_sheet!$D:$D, All_units,IF(Main_next_unit_name="",SUM(COUNTIFS(Saif_col,INDIRECT("parameters!D"&Main_unit_row+1&":O"&Last_unit_row))),SUM(COUNTIFS(Saif_col,INDIRECT("parameters!D"&Main_unit_row+1&":O"&Main_next_unit_row-1)))), One_unit,SUM(COUNTIFS(Saif_col,INDIRECT("parameters!D"&Unit_row&":o"&Unit_row))), IF($B$2="all",All_units,One_unit))
E2E2=LET( Start_row,16, find_row,MATCH($B$2,parameters!$B$17:$B$51,0)+Start_row, MAX(IF(Total_sheet!$D:$D=INDIRECT("parameters!$D"&find_row&":$O"&find_row),Total_sheet!E:E)))
F2F2=$C$2/$D$2
A7:E13A7=LET( Main_unit_row,MATCH($A$2,parameters!$A$16:$A$61,0)+15, Main_next_unit_name,INDEX(parameters!$A$3:$F$3,MATCH($A$2,parameters!$A$3:$F$3,0)+1), Main_next_unit_row,MATCH(Main_next_unit_name,parameters!$A$16:$A$61,0)+15, Unit_row,MATCH($B$2,parameters!$B$17:$B$52,0)+16, Saif_col,Total_sheet!$D:$D, Unit_seifim_all,INDIRECT("parameters!$d"&Main_unit_row_row&":$o"&Main_next_unit_row), Unit_seifim1,INDIRECT("parameters!$d"&Unit_row&":$o"&Unit_row), All_unit,FILTER(FILTER(Total_sheet!$A:$E,ISNUMBER(MATCH(Saif_col,Unit_seifim1,0))),{1,1,1,1,1}), One_unit,FILTER(FILTER(Total_sheet!$A:$E,ISNUMBER(MATCH(Saif_col,Unit_seifim1,0))),{1,1,1,1,1}), IF($B$2="all",All_unit,One_unit))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
A2List=parameters!$A$3:$F$3
B2List=OFFSET(parameters!$A$3,1,MATCH($A2,parameters!$A$3:$F$3,0)-1,COUNTA(OFFSET(parameters!$A$3,1,MATCH($A2,parameters!$A$3:$F$3,0)-1,15)),1)
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
It's impossible to say without seeing the other worksheets referenced in the formulae. And even then, I'm not sure I have the stamina to wade through these formulae ...

But I do note:

A7: =IF($B$2="all",All_unit,One_unit) where your LET() defines All_unit and One_unit identically! Presumably All_unit should refer to Unit_seifim_all rather than Unit_seifim1?

And if A7# contains All/filtered results, couldn't you simply have:

C2: =SUM(INDEX(A7#,,5))
D2: =ROWS(A7#)
E2: =MAX(INDEX(A7#,,5))
 
Upvote 0
Ooops, you are right, I left mistakes at the LET().
Basically the question sums to the problem that the FILTER funcion, doesn't give results when the range refers to more then one row (like here: INDIRECT("parameters!$d47:$o52"), while it gives the right results when there is only one row (like here: INDIRECT("parameters!$d47:$o47").
Does it make sense?
 
Upvote 0
I suspect your problem is with the MATCH.

If I'm following this correctly, your A7 formula for All_unit, when corrected, will contain:
MATCH(Saif_col,Unit_seifim_all,0)

which will look something like: MATCH(Total_sheet!$D:$D, parameters!$d47:$o52,0)

MATCH's 2nd argument lookup_array needs to be a single row or single column, so this formula will return a column of N/A.
 
Upvote 0
Now I get it.
Can you suggest a formula that will solve my problem?
Many many THX
 
Upvote 0
Can you suggest a formula that will solve my problem?
I can try, but it's not clear what you're doing when we can't see your layout.

Can you post a simple example to show how you want your MATCH to work?
 
Upvote 0
Here is the sheet with all the formulas (I succeeded to solve the problem with he XL2BB).
The problem I would like to solve is how to make the Filter function works when I select the ALL option in cell B2.
thx
Nati


excel_question.xlsx
ABCDE
1group to choosesubgroup to choosetotal priceitemsaverage
2group2subgroup2751,254.12317,084.71
3
4
5
6cat_numdata1data2codeprice
72547data145data1552250022367.6
82773data234data2442250016455.22
92904data287data2972250012431.3
10
stats
Cell Formulas
RangeFormula
C2C2=LET( Main_unit_row,MATCH($A$2,parameters!$A$16:$A$61,0)+15, Main_next_unit_name,IFERROR(INDEX(parameters!$A$3:$F$3,MATCH($A$2,parameters!$A$3:$F$3,0)+1),""), Main_next_unit_row,MATCH(Main_next_unit_name,parameters!$A$16:$A$61,0)+15, Unit_row,MATCH($B$2,parameters!$B$17:$B$61,0)+16, Last_unit_row,SUMPRODUCT(MAX(ROW(parameters!$B:$B)*(parameters!$B:$B<>""))), Old_salary_col,Total_sheet!$E:$E, Saif_col,Total_sheet!$D:$D, All_units,IF(Main_next_unit_name="",SUM(SUMIFS(Old_salary_col,Saif_col,INDIRECT("parameters!D"&Main_unit_row+1&":O"&Last_unit_row))),SUM(SUMIFS(Old_salary_col,Saif_col,INDIRECT("parameters!D"&Main_unit_row+1&":O"&Main_next_unit_row-1)))), One_unit,SUM(SUMIFS(Old_salary_col,Saif_col,INDIRECT("parameters!D"&Unit_row&":o"&Unit_row))), IF($B$2="all",All_units,One_unit))
D2D2=LET( Main_unit_row,MATCH($A$2,parameters!$A$16:$A$61,0)+15, Main_next_unit_name,IFERROR(INDEX(parameters!$A$3:$F$3,MATCH($A$2,parameters!$A$3:$F$3,0)+1),""), Main_next_unit_row,MATCH(Main_next_unit_name,parameters!$A$16:$A$61,0)+15, Unit_row,MATCH($B$2,parameters!$B$17:$B$61,0)+16, Last_unit_row,SUMPRODUCT(MAX(ROW(parameters!$B:$B)*(parameters!$B:$B<>""))), Old_salary_col,Total_sheet!$E:$E, Saif_col,Total_sheet!$D:$D, All_units,IF(Main_next_unit_name="",SUM(COUNTIFS(Saif_col,INDIRECT("parameters!D"&Main_unit_row+1&":O"&Last_unit_row))),SUM(COUNTIFS(Saif_col,INDIRECT("parameters!D"&Main_unit_row+1&":O"&Main_next_unit_row-1)))), One_unit,SUM(COUNTIFS(Saif_col,INDIRECT("parameters!D"&Unit_row&":o"&Unit_row))), IF($B$2="all",All_units,One_unit))
E2E2=$C$2/$D$2
A7:E9A7=LET( Main_unit_row,MATCH($A$2,parameters!$A$16:$A$61,0)+15, Main_next_unit_name,INDEX(parameters!$A$3:$F$3,MATCH($A$2,parameters!$A$3:$F$3,0)+1), Main_next_unit_row,MATCH(Main_next_unit_name,parameters!$A$16:$A$61,0)+15, Unit_row,MATCH($B$2,parameters!$B$17:$B$52,0)+16, Saif_col,Total_sheet!$D:$D, Unit_seifim_all,INDIRECT("parameters!$d"&Main_unit_row&":$o"&Main_next_unit_row), Unit_seifim1,INDIRECT("parameters!$d"&Unit_row&":$o"&Unit_row), All_unit,FILTER(FILTER(Total_sheet!$A:$E,ISNUMBER(MATCH(Saif_col,Unit_seifim_all,0))),{1,1,1,1,1}), One_unit,FILTER(FILTER(Total_sheet!$A:$E,ISNUMBER(MATCH(Saif_col,Unit_seifim1,0))),{1,1,1,1,1}), IF($B$2="all",All_unit,One_unit))
Dynamic array formulas.
Cells with Data Validation
CellAllowCriteria
A2List=parameters!$A$3:$F$3
B2List=OFFSET(parameters!$A$3,1,MATCH($A2,parameters!$A$3:$F$3,0)-1,COUNTA(OFFSET(parameters!$A$3,1,MATCH($A2,parameters!$A$3:$F$3,0)-1,15)),1)
 
Upvote 0
I did it :)

My problem was with the function in A7 : All_unit,FILTER(FILTER(Total_sheet!$A:$E,ISNUMBER(MATCH(Saif_col,Unit_seifim_all,0))),{1,1,1,1,1}),
Where the Match cannot work with an array but only with a row (in my formula).
The solution I found is:
All_unit,FILTER(FILTER(Total_sheet!$A:$E,(COUNTIF(Unit_seifim_all,Saif_col)>0)),{1,1,1,1,1}),

Thx to all the help I got here

Nati
 
Upvote 0
Solution

Forum statistics

Threads
1,215,048
Messages
6,122,862
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top