Return the frequent value or the maximum value in one formula

Israelinas

New Member
Joined
Dec 25, 2016
Messages
25
Hi all,

It is a quite complicate formula, but I hope this is the right place.

I have a long list which presents (A) account id, (B) date, and (C) amount.
I have sorted the data according to the levels below:
1) account id - from biggest to smallest (doesn't really matter).
2) date from newest to oldest.

Now I am trying t build a formula that will return the correct value for me:
1) return the frequent (C) amount for each (A) account id.
2) If there isn't frequent one, return the maximum between them.

for example:
CASE 1:
I have 3 rows for account id: 571638.
for each row I have date: 1st with 30/09/2018, 2nd with 31/08/2018, 3rd with 31/07/2018.
for each row I have amount: 1st with 3,880, 2nd with 3,880, 3rd with 5,144.

In this case I want to get the frequent amount (3,880)


CASE 2:
all is the same instead of the amount: 1st with 3,880, 2nd with 3,980, 3rd with 4,150.

In this case I want to get the maximum.

Hope you can help me.

Many thanks
Salinas
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try:

ABCDEFG
AccountDateAmountAccountMode or Max
571638

<tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]571638[/TD]
[TD="align: right"]9/30/2018[/TD]
[TD="align: right"]3880[/TD]
[TD="align: right"][/TD]

[TD="align: right"]3880[/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]571638[/TD]
[TD="align: right"]8/31/2018[/TD]
[TD="align: right"]3880[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]571638[/TD]
[TD="align: right"]7/31/2018[/TD]
[TD="align: right"]5144[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]1234566[/TD]
[TD="align: right"]6/30/2018[/TD]
[TD="align: right"]1234[/TD]
[TD="align: right"]>[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet11

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]F2[/TH]
[TD="align: left"]{=IFERROR(MODE(IF($A$2:$A$10=E2,$C$2:$C$10)),MAX(IF($A$2:$A$10=E2,$C$2:$C$10)))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
Try:

ABCDEFG
AccountDateAmountAccountMode or Max
571638

<tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]

[TD="align: right"][/TD]

[TD="align: center"]2[/TD]
[TD="align: right"]571638[/TD]
[TD="align: right"]9/30/2018[/TD]
[TD="align: right"]3880[/TD]
[TD="align: right"][/TD]

[TD="align: right"]3880[/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"]571638[/TD]
[TD="align: right"]8/31/2018[/TD]
[TD="align: right"]3880[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"]571638[/TD]
[TD="align: right"]7/31/2018[/TD]
[TD="align: right"]5144[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]
[TD="align: right"]1234566
[/TD]
[TD="align: right"]6/30/2018[/TD]
[TD="align: right"]1234[/TD]
[TD="align: right"]>[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Sheet11

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<tbody>[TR]
[TH]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
[TR]
[TH]F2[/TH]
[TD="align: left"]{=IFERROR(MODE(IF($A$2:$A$10=E2,$C$2:$C$10)),MAX(IF($A$2:$A$10=E2,$C$2:$C$10)))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself
[/TD]
[/TR]
</tbody>[/TABLE]

Many thanks Eric!

The formula is what I am looking for, but in my case, I have a thousands of different account numbers (for each one can be more than one row), so I think I need to combine this formula with MATCH or VLOOKUP or any other formula? How can I do it?


Thanks,
Salinas
 
Upvote 0
I'm not entirely sure what you're asking, but if you want to perform the same formula for multiple accounts, just put the next account in E3, and copy the F2 formula to F3. You can add an entire column of accounts this way. Just make sure the ranges in the formula match your source data range.
 
Upvote 0
Hi,

I mean I have a list of almost 50k rows with different account numbers when some of them are duplicated with a different date and different or same amount.
I tried to copy and paste transpose, but I have too many rows, so it cannot be converted to columns.

COLUMN [A] ACCOUNT
11223344
11223344
11223344
44332211
44332211
55667788
77889911
22557788
22557788

COLUMN DATE (different date for every row)

COLUMN [C] AMOUNT

1000
1000
1100
100
1500
2000
1300
2000
2000

Hope now it's more clear.

Many thanks,
Salinas
 
Upvote 0
I'm not sure that it is yet clear.

What result (& why) do you want for these values of columns A & C? (I note that Eric's formula returns 5. Whilst 5 is one of the most frequent numbers, there are others just as frequent. Nor is it the highest number)

In case it isn't clear from the previous answer, what result do you want if the column D numbers were moved to column C?


Excel 2016
ABCD
1
21122334455
31122334455
41122334495
511223344916
61122334467
71122334477
81122334477
Sample
 
Last edited:
Upvote 0
you can use following array formula.

=IF(ISNA(MODE(IF(A$2:A$9=A2,IF(B$2:B$9=B$2:B$9,B$2:B$9)))),MAX(IF(A$2:A$9=A2,B$2:B$9)),MODE(IF(A$2:A$9=A2,IF(B$2:B$9=B$2:B$9,B$2:B$9))))
 
Upvote 0
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ACCOUT
[/TD]
[TD]DATE
[/TD]
[TD]AMOUNT
[/TD]
[TD]
WHAT I NEED TO BE RETURNED
[/TD]
[TD]REASON
[/TD]
[/TR]
[TR]
[TD]11223344
[/TD]
[TD]30/09/2018
[/TD]
[TD]1000
[/TD]
[TD]1000
[/TD]
[TD]Frequent amount for the same account
[/TD]
[/TR]
[TR]
[TD]11223344
[/TD]
[TD]31/08/2018
[/TD]
[TD]1000
[/TD]
[TD]1000
[/TD]
[TD]Frequent amount for the same account
[/TD]
[/TR]
[TR]
[TD]11223344
[/TD]
[TD]31/07/2018
[/TD]
[TD]1100
[/TD]
[TD]1000
[/TD]
[TD]Frequent amount for the same account
[/TD]
[/TR]
[TR]
[TD]44332211
[/TD]
[TD]30/09/2018
[/TD]
[TD]100
[/TD]
[TD]1500
[/TD]
[TD]Maximum amount for the same account
[/TD]
[/TR]
[TR]
[TD]44332211
[/TD]
[TD]31/08/2018
[/TD]
[TD]1500
[/TD]
[TD]1500
[/TD]
[TD]Maximum amount for the same account
[/TD]
[/TR]
[TR]
[TD]55667788
[/TD]
[TD]30/09/2018
[/TD]
[TD]2000
[/TD]
[TD]2000
[/TD]
[TD]Only one row for this account
[/TD]
[/TR]
[TR]
[TD]77889911
[/TD]
[TD]30/09/2018
[/TD]
[TD]1300
[/TD]
[TD]1300
[/TD]
[TD]Only one row for this account
[/TD]
[/TR]
[TR]
[TD]22557788
[/TD]
[TD]30/09/2018
[/TD]
[TD]2000
[/TD]
[TD]2000
[/TD]
[TD]Frequent amount for the same account
[/TD]
[/TR]
[TR]
[TD]22557788
[/TD]
[TD]31/08/2018
[/TD]
[TD]2000
[/TD]
[TD]2000
[/TD]
[TD]Frequent amount for the same account
[/TD]
[/TR]
[TR]
[TD]22557788
[/TD]
[TD]31/07/2018
[/TD]
[TD]2000
[/TD]
[TD]2000
[/TD]
[TD]Frequent amount for the same account
[/TD]
[/TR]
</tbody>[/TABLE]

Hi Peter,

The formula that Eric wrote is correct but only for static values.
I need to drag the formula down and the range is changed, and if I choose the whole column as a range it still returns incorrect values.
I need to find a way to make a group for every account, so the formula range will be only rows for the relevant account number.
Please see the table above as an example (in the real table I have 50K rows).


Thanks,
Salinas
 
Upvote 0
Please see the table above as an example
Your table does not address the questions that I asked.

What result (& why) do you want for these values of columns A & C?

In case it isn't clear from the previous answer, what result do you want if the column D numbers were moved to column C?


Excel 2016
ABCD
1
21122334455
31122334455
41122334495
511223344916
61122334467
71122334477
81122334477
Sample
 
Upvote 0
Your table does not address the questions that I asked.

Hi Peter,

I understand your question, it is very good question.
I forgot to mention that in my case I don't have more than 3 rows for the same account number.

Hope this can help.


Many thanks for your help and reply.
Salinas
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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