+ Reply to Thread
Results 1 to 4 of 4

Nested Functions collapsing data into #VALUE but I can't know why

Hybrid View

  1. #1
    Registered User
    Join Date
    06-15-2023
    Location
    United States
    MS-Off Ver
    2305
    Posts
    1

    Nested Functions collapsing data into #VALUE but I can't know why

    (sample Workbook attached)

    I've written a function to take an input range, and output that same data with an added column containing the COUNTIF of the values in the first column.

    =LET(inputRange,B1:D16,LET(key, CHOOSECOLS(inputRange,1),HSTACK(inputRange, COUNTIF(key, CHOOSECOLS(key,1)))))

    The COUNTIF column ends up filled with #VALUE! errors, but the original input range prints out just fine. When I walk through the Evaluate Formula steps it looks like the inputRange is #N/A-ing out (but only in the evaluator - adding an IF(ISNA(inputrange) into my function doesn't trigger), but that appears to cause the COUNTIF data (which somehow still evaluates despite the #N/A's???) to collapse into a #VALUE! error. I don't know why it's happening or how to fix it.

    Breaking out only the HSTACK by itself and manually inputting the ranges the LET statements would generate correctly outputs what I want, but I don't know why it suddenly fails inside the LET statements.

    =HSTACK(B1:D16, COUNTIF(B1:D16,B1:B16))

    PLEASE NOTE: for background reasons I need to do this in a formula: using an automate script, macro, or VBA script are - unfortunately - not acceptable solutions in this situation.
    Attached Files Attached Files

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Nested Functions collapsing data into #VALUE but I can't know why

    Hmm, this works:
    Formula: copy to clipboard
    =LET(inputRange,B1:D16,CHOOSECOLS(HSTACK(inputRange,COUNTIF(inputRange,inputRange)),1,2,3,4))
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,740

    Re: Nested Functions collapsing data into #VALUE but I can't know why

    The choosecols functions returns an array not a range, hence the errors, but you can use Take instead
    Formula: copy to clipboard
    =LET(inputRange,B1:D16,LET(key,TAKE(inputRange,,1),HSTACK(inputRange,COUNTIF(key,CHOOSECOLS(key,1)))))
    or slightly shorter
    =LET(inputRange,B1:D16,key,TAKE(inputRange,,1),HSTACK(inputRange,COUNTIF(key,key)))

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,757

    Re: Nested Functions collapsing data into #VALUE but I can't know why

    Quote Originally Posted by Fluff13 View Post
    or slightly shorter
    Yes, OP should note that LET allows you to define multiple variables so it is not necessary to nest LET functions.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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] How to apply nested IF functions in data validation
    By adriano.r.marques in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-29-2015, 06:01 PM
  2. Replies: 6
    Last Post: 03-17-2015, 01:35 AM
  3. [SOLVED] Collapsing or Un-Collapsing Grouped Rows using VBA
    By rz6657 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-24-2015, 12:39 PM
  4. Collapsing data in table
    By shhhhh22 in forum Excel General
    Replies: 4
    Last Post: 01-19-2012, 12:27 AM
  5. Collapsing a data set
    By cj21 in forum Excel General
    Replies: 2
    Last Post: 11-28-2011, 11:11 AM
  6. Excel 2007 : Grouping and collapsing data
    By bond002 in forum Excel General
    Replies: 2
    Last Post: 07-28-2010, 10:08 PM
  7. Collapsing Repeated Data
    By teddybouch in forum Excel General
    Replies: 7
    Last Post: 07-11-2008, 04:24 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