+ Reply to Thread
Results 1 to 5 of 5

Formula for Pivots - INDEX/MATCH, Nested IF

  1. #1
    Registered User
    Join Date
    10-21-2016
    Location
    Kansas City, MO
    MS-Off Ver
    2010, 2013
    Posts
    75

    Formula for Pivots - INDEX/MATCH, Nested IF

    I am looking at online sales data reports in Excel where records are divided by product by order (i.e. an order with 2 different products would have 2 different rows). An order can have an "Order-Level Discount," a "Product-Level Discount," or both. I am trying to sort through these quickly depending on which discount type(s) is/are associated with which order(s). I want to execute a pivot table that, as shown in my "Sample Records" attachment, looks through all of the lines for each order and determines what discount or discount combination is present. I do not think this can be done without a formula, but I do not understand which formula I need since it must consider multiple order records. Intuitively, it feels like an INDEX/MATCH within a Nested IF or an array formula of some kind, but those assumptions may not be right.

    Any help would be appreciated!
    Attached Files Attached Files

  2. #2
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Formula for Pivots - INDEX/MATCH, Nested IF

    In F1 try:
    Please Login or Register  to view this content.
    But if you just need a Pivot Table, couldn't you put "Order ID" in the Row Labels, then "Sum of Product-Level Discount" and "Sum of Order-Level Discount" in the Values; and then let the numbers in that speak for themselves without grinding through some text lookup?
    Click the [* Add Reputation] Button to thank people for help!
    Post Attachment: Click [Go Advanced] under the reply box; then click [Manage Attachments] to launch the attachments dialogue.
    Mark Thread Solved: Go to the top of the first post; Select [Thread Tools] dropdown; Pick the [Mark thread as Solved] option.

  3. #3
    Registered User
    Join Date
    10-21-2016
    Location
    Kansas City, MO
    MS-Off Ver
    2010, 2013
    Posts
    75

    Re: Formula for Pivots - INDEX/MATCH, Nested IF

    Thanks, Ben_Hensel. Your formula works, but could you please help me understand what it's saying? I've tried reading about the CHOOSE function but it is not making sense to me. I understand how SUMIF works, so I get that aspect of the formula. And I understand "CHOOSE" selects from a range of values based on an index. But the reference to "1" and "2", adding and multiplying SUMIF, and the order in which you list the output values - those things I don't understand.

    Unfortunately, summing the PL discounts and OL discounts won't work for my pivot because I can have an unlimited number of rows per order. If I set the values to 1 (OL only), 2 (PL only), 3 (Both), or 4 (Check), and a pivot order returns "12", I could be looking at a 12-line order with OL-only discounts; a 6-line order with PL-only discounts; a 5-line order with two "Both", 1 "OL", and 1 "PL"; etc.

    I realized after writing this I would need to return numerical values since the values section of my pivot would not return text (I could easily substitute the outputs for numbers in the formula, run the pivot, copy as a table, and INDEX/MATCH to text string values). I would appreciate if you kept explaining the formula using the text string values, though, as I won't confuse those with numerical reference locations.
    Last edited by eNinjaInTraining; 02-09-2018 at 10:37 AM.

  4. #4
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Formula for Pivots - INDEX/MATCH, Nested IF

    CHOOSE is pretty much a Case structure. Something like this:
    CHOOSE(math, return 1, return 2, return 3, etc)

    So you do some math in the first term of the choose, and it must produce an integer between 1 and 255. And then the CHOOSE returns the term of the function that matches the integer from the first term.

    It's basically a CASE structure.

    So what I was doing in the first term of the CHOOSE was Boolean arithmetic.

    Fundamentally what's going on is,
    TRUE assess as 1 if you use it in math, and FALSE assesses as zero

    So 1+ (sum1 >0) + 2*(sum2 >0)
    If those (sum >0) assesses as TRUE, it gets a one, if it's FALSE, a zero.

    So it works out as 1+ IF(sum1 >0, 1, 0) + (sum2 >0, 2, 0)
    Returns 1 if neither is true (because 1+0+0), returns 2 if it's "OL only" (1+1+0), 3 if it's "PL only" (1+0+2), and 4 if it's both (1+1+2)

    Then those numbers get fed into CHOOSE.

  5. #5
    Registered User
    Join Date
    10-21-2016
    Location
    Kansas City, MO
    MS-Off Ver
    2010, 2013
    Posts
    75

    Re: Formula for Pivots - INDEX/MATCH, Nested IF

    I think I get it, ben_hensel - thanks for your insight. That's quite an advanced formula you built, and I am impressed!

+ 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. Trouble with nested index match formula
    By jamesplant77 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-30-2016, 10:44 AM
  2. Nested IF Index Match formula reached limit. Suggestions?
    By patrickt in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-06-2015, 03:04 AM
  3. [SOLVED] Help Requested with Nested Small Function Inside Index/Match Formula
    By trandle in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-26-2015, 10:07 AM
  4. Replies: 8
    Last Post: 12-31-2014, 11:48 AM
  5. Help with nested Index Match formula
    By LilSisKin in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-09-2013, 06:10 PM
  6. Nested Match(index()) vs. Match() array formula.
    By GeneralDisarray in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-14-2011, 07:57 AM
  7. Dependent Percentile Formula in Table with Nested Lookup or Index Match?
    By chogan in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-11-2010, 06:34 PM

Tags for this Thread

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