Sort Option For Filter Function?

shellp

Board Regular
Joined
Jul 7, 2010
Messages
199
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hello

I am using Excel 365 and summarizing from a data table. Below gives me the data that I want but a) is it possible to programmatically format columns D and F with 1 decimal point and a % sign; and b) how can I programmatically sort column 6 (F) in descending order? Thanks for any and all assistance.

VBA Code:
=LET(CC,(UNIQUE(FILTER(C_MRP,(C_Serv=J1)*(C_Date>=H1)*(C_Date<=H2)*(C_Denom>0)))),
CHOOSE({1,2,3,4,5,6,7},CC,COUNTIFS(C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0",C_Status,"=Y"),
COUNTIFS(C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0",C_Status,"=D"),
ROUND(COUNTIFS(C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0",C_Status,"=Y")*100/SUMIFS(C_Denom,C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0"),1),
COUNTIFS(C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0",C_Status,"=N"),
ROUND(COUNTIFS(C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0",C_Status,"=N")*100/SUMIFS(C_Denom,C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0"),1),
SUMIFS(C_Denom,C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0")))

Results (minus the sort):

1702962254485.png
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
In simple terms: =LET(x,SomeArrayFormula,SORT(x,6,-1))

Or in your case, more like: =LET(CC,YourFormula,x,YourBigFormulaUsingCC,SORT(x,6,-1))

But your formula looks unnecessarily complicated. You're filtering C_MRP on four criteria, but then building those same criteria into several COUNTIFS and SUMIFS?
...is it possible to programmatically format columns D and F with 1 decimal point and a % sign

I'm not clear what you mean by programmatically? Any reason you can't simply manually format the cells?

You can use the TEXT function in a formula to display a number in a particular format. This can be handy when you want to incorporate a number into text, e.g. the first example below.
But I wouldn't use this to "format" numbers, because then they are no longer numbers, e.g 2nd example below.

Cell Formulas
RangeFormula
A1A1=TODAY()
B1B1="Today is "&TEXT(A1,"dddd")
B2B2=TEXT(A2,"0.0%")
 
Upvote 0
Hello,

Thank you so much for your reply. I am just learning about this function so I am not understanding what you mean by it being unnecessarily complicated....how can I get MRP but then the calculated columns as well? Thanks.

Shelley
 
Upvote 0
Looks like you can slim down the formula like
Excel Formula:
=LET(CC,(UNIQUE(FILTER(C_MRP,(C_Serv=J1)*(C_Date>=H1)*(C_Date<=H2)*(C_Denom>0)))),
a,COUNTIFS(C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0",C_Status,"=Y"),
b,SUMIFS(C_Denom,C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0"),
c,COUNTIFS(C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0",C_Status,"=N"),
SORT(CHOOSE({1,2,3,4,5,6,7},CC,a,COUNTIFS(C_Serv,J1,C_MRP,CC,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0",C_Status,"=D"),ROUND(a*100/b,1),c,ROUND(c*100/b,1),b),6,-1))
 
Upvote 0
... I am not understanding what you mean by it being unnecessarily complicated....
I should have said unnecessarily long, which was my quick impression based on the same filters being applied several times.

A shorter version (and probably able to be further shortened) that should work for you?

=LET(CC,FILTER(CHOOSE({1,2},C_MRP,C_Status),(C_Serv=J1)*(C_Date>=H1)*(C_Date<=H2)*(C_Denom>0)),nm,TAKE(CC,,1),status,TAKE(CC,,-1),u,UNIQUE(nm),Y,BYROW(u,LAMBDA(r,SUM((status="Y")*(nm=r)))),N,BYROW(u,LAMBDA(r,SUM((status="N")*(nm=r)))),D,BYROW(u,LAMBDA(r,SUM((status="D")*(nm=r)))),T,Y+N+D,SORT(CHOOSE({1,2,3,4,5,6,7},u,Y,D,Y/T,N,N/T,T),6,-1))
 
Upvote 0
Solution
Or another way without using FILTER:

=LET(c,COUNTIFS(C_MRP,C_MRP,C_Status,{"Y","D","N"},C_Serv,J1,C_Date,">="&H1,C_Date,"<="&H2,C_Denom,">0"),x,UNIQUE(HSTACK(C_MRP,c,BYROW(c,LAMBDA(r,SUM(r))))),t,TAKE(x,,-1), SORT(HSTACK(TAKE(x,,3),INDEX(x,,2)/t,INDEX(x,,4),INDEX(x,,4)/t,t),6,-1))
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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