+ Reply to Thread
Results 1 to 18 of 18

Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

  1. #1
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    I have a large table of consumption records for various account numbers and locations. The account numbers are assigned to various locations, some locations have more than one account number. I am working on a report that will pull the 10 highest records for a given month and year. I am currently using the following array formula in A6:A15 to retrieve the top 10 locations by their consumption for a given month and year selected in C2 and C3, respectively:

    Please Login or Register  to view this content.
    and in B6:B15, the following array formula retrieves the consumption value for that location:

    Please Login or Register  to view this content.
    Both of these formulas are working, except

    1) they sometimes return duplicate values and
    2) for those locations with multiple accounts, it retrieves each account for that location on a new line and I would like it to sum the consumption and return the location only once

    As a more general question, is there a more efficient way to achieve what the two formulas above are doing? Thank you all!!
    Attached Files Attached Files

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    With PowerQuery (add-in for Ex2013)

    is that what you want? (green table)
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    Yes, that is what I expect. Thank you. I would still prefer a formulaic solution.

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    No problem
    Have a nice day

  5. #5
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    AA=INDEX(_t[Location],AGGREGATE(15,6,ROW(_t[Year])/(_t[Metered Consumption]=B6)/(_t[Month Name]=$C$2)/(_t[Year]=$C$3),COUNTIF($B$6:B6,B6))-1)
    BB=AGGREGATE(14,6,_t[Metered Consumption]/(_t[Month Name]=$C$2)/(_t[Year]=$C$3),ROW($A1))
    non array
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    I only just came across another post about Aggregate an hour ago. It seems to be crazy powerful. It looks to do exactly what I need!

    I'll look into the syntax further, but I think I can see what it does.

  7. #7
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    Hi all- The solution in post #5 does not fulfill this requirement:
    Quote Originally Posted by TFiske View Post
    ...2) for those locations with multiple accounts,... I would like it to sum the consumption and return the location only once.
    In the attached file, I have employed a named formula - basically a virtual column - which adds the first tabular position of each location (divided by 10000) to a period- and location-specific SUMIFS. This yields PeriodSums, an array of totals differentiated by location:
    Please Login or Register  to view this content.
    The next formula returns the location having the k-th largest consumption for the specified period, with k indicating position in the Top Ten table. Note that PeriodSums contains multiple (duplicate) entries per location. The construction IFNA((FREQUENCY(PeriodSums,PeriodSums)>0)*PeriodSums,0) effectively removes the duplicates, producing an array for the LARGE function to process. The result is then "unpacked"; the integer portion is discarded, and the remainder multiplied by 10000 to give the INDEX function the tabular position of the location name. (Locations with 0 consumption return ""). Paste this ARRAY FORMULA* in A6 and copy down:
    Please Login or Register  to view this content.
    ... and this simple SUMIFS in B6, copied down:
    Please Login or Register  to view this content.
    Please note, column A is a complex formula. It requires about 10 seconds to calculate new inputs.

    *Always press CTRL+SHIFT+ENTER to confirm entry after pasting or editing an ARRAY FORMULA in the Formula Bar.
    When copying the formula to other cells, make sure the copied cell is not part of the Paste Area.
    Attached Files Attached Files
    Last edited by leelnich; 12-01-2017 at 05:14 PM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  8. #8
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    Interesting,

    tim201110's solution seems to do what I need. I'll look at your attachment and compare. Thank you!

  9. #9
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    leelnich,

    You are indeed correct. The sums are not returning properly using the solution in post #5. Your solution appears to use a great deal of processor power. In the actual workbook, your formula would be evaluating a table of consumption records going back to 2009. The table is over 6000 rows long, is this still a reasonable solution to the problem given the size of the data set?

  10. #10
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    Debatable. I really hate any formula that takes longer than 4 seconds to calc, but you may be able to live with slow if the inputs rarely change. I'm trying a different approach, I'll get back to you...
    Last edited by leelnich; 12-01-2017 at 08:04 PM.

  11. #11
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    So, let me see if I can understand what your first formula is doing?

    PeriodSums is operating in a similar way to CONCATENATE in that it generates an "address", for lack of a better word, for each row in the Consumption Records table.

    Where you loose me is in the 2nd formula. I understand that INT would reduce each value generated by PeriodSums to a unique Integer, but I don't see how that relates to "Location" as the [value if true] part of the IF statement.

    I can see how MOD would then "reattach" a particular remainder to the unique Integer generated by the INT function and arrive at a unique value. Am I wrapping my head around this or am I totally off track, ;-)?

    Finally, I have used FREQUENCY a few times but can you explain a little more how it removes the duplicates. Thank you, thank you. This is fascinating!
    Last edited by TFiske; 12-01-2017 at 05:30 PM.

  12. #12
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    Quote Originally Posted by leelnich View Post
    Debatable. I really hate any formula that takes longer than 4 seconds to calc, but you may be able to live with slow if the inputs rarely change. I'm trying a different approach, I'll let get back to you...
    I suppose an intermediate solution would be for me break the Workbook apart, year by year, so that I'm not asking the formula to evaluate early as much data at once.

  13. #13
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    OK, this is calculating in under a second for me. I instituted a 2-column helper area (columns G:H in the sample, but you can move them elsewhere). Column H is a list of locations with duplicates removed (which allows us to drop the FREQUENCY function). Column G is like PeriodSums - it appends each location's tabular position to its SUMIFS value as a means of differentiation- but it's much more efficient as a worksheet formula calculated just once per unique entry.

    The helper columns are named Psums (= Sheet2!$G$2:$G$201) and Locations (= Sheet2!$H$2:$H$201)

    The formula to list unique Locations - paste in H2 and copy down (I allowed for 200 locations in the sample):
    Please Login or Register  to view this content.
    ... and for differentiated Psums - paste in G2 and down:
    Please Login or Register  to view this content.
    Now for the main Top Ten formula, Psums can be plugged straight into the LARGE function:
    Please Login or Register  to view this content.
    ...while we can skip re-calculating the SUMIFS, and instead just lookup the value.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by leelnich; 12-02-2017 at 12:55 AM.

  14. #14
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Thumbs up Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    This is pretty amazing. I'd give you more rep, but it says I need to "spread some rep around" first.

    I think I have a better grasp of what you're doing with seeing the various parts of the formula broken out.

    One question, there is an occasional anomaly in the data set where the consumption values for an account are negative, I'm sure you noticed. This is a quirk of how the Utilities Department sometimes edits consumption and not anything I can control. Obviously, those will never appear in the top 10 list, just wondering how this approach might be affected by negative values.

    I can see several applications for this approach across some other projects I'm working on.

    I'll implement your solution in my working sheet on Monday. I will mark this as solved.

    I may have some questions re. your formulas and this tabular positioning you're using,
    can I contact you privately through the forum or would you prefer I stick to the thread?

    Either way, Thank you, this is great!
    Last edited by TFiske; 12-01-2017 at 09:23 PM.

  15. #15
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    Yes, I noticed the negative adjustments. Here's CONSUMPTION for the month of OCT 2017, with zero and blank amounts filtered out:

    Untitled.png

    As you can see, the top 3 lines all reference DALBEY MEMORIAL PARK, with consumptions of -1, 5, and 7. As written, the formulas incorporate negatives in the total, so DALBEY's OCT total is 11, but you could add another criteria to the SUMIFS to filter them out.

  16. #16
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    Quote Originally Posted by TFiske View Post
    ...I may have some questions re. your formulas and this tabular positioning you're using,
    can I contact you privately through the forum or would you prefer I stick to the thread?
    You may P.M. me and/or stick with this thread for further amplification, but the best approach if you have new requirements is to start a new thread (and perhaps include a link to this one, if related). That will get fresh eyes and minds on it.

    and...You're welcome, thanks for the rep! Note: awarding rep to ALL who gave their time and effort to your request is always appreciated!

  17. #17
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    IMHO To build complicated formulas is very exiting, but in his case one should use a simple Pivot table
    or formulas, but quite simple ones
    Attached Files Attached Files
    Last edited by tim201110; 12-02-2017 at 10:41 AM.

  18. #18
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sum duplicate values returned by array formula INDEX(MATCH(LARGE(IF)))

    Hi @tim201110. I took a look at your submissions. I had two issues with the Pivot Table solution. 1) the entries should be sorted automatically and 2) the negative values mentioned in posts #14-15 aren't included in the totals. Since I don't know Pivot Tables (yet), I can't say how easy these would be to fix.

    On the other hand, I really liked your Formula-based solution. As fast as my approach, with less impact on calculation speed when new records are added to the CONSUMPTION RECORDS table. I took the liberty of making a few changes. Please see the attached file for a complete description.
    Nicely done! - Lee
    Attached Files Attached Files
    Last edited by leelnich; 12-02-2017 at 07:20 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Index Match Large Duplicate Values
    By lalahaedong_excel in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 09-22-2017, 01:05 PM
  2. Replies: 2
    Last Post: 03-15-2017, 08:22 AM
  3. [SOLVED] Index Match Large Duplicate Values
    By auxaurores in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-12-2016, 05:02 AM
  4. [SOLVED] INDEX, MATCH & LARGE trouble with duplicate values
    By paulstuartbullock in forum Excel General
    Replies: 4
    Last Post: 08-04-2015, 11:17 PM
  5. [SOLVED] Help with Index/Match/Large problem with duplicate values
    By enphynity in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-31-2013, 09:56 AM
  6. [SOLVED] Long array formula with INDEX and MATCH quits working when range is too large
    By UncleKevy in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-05-2013, 09:42 PM
  7. Duplicate values returned using Index Match Lookup with Small()
    By jacob@thepenpoint in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-18-2013, 10:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1