+ Reply to Thread
Results 1 to 14 of 14

Array Formula which ignores blank cells / only calculates cells with values

  1. #1
    Registered User
    Join Date
    05-22-2020
    Location
    Leningrad
    MS-Off Ver
    2007
    Posts
    34

    Array Formula which ignores blank cells / only calculates cells with values

    Hi All,

    In this example I have a table of data in cells A2 to Z100. Based on the data elsewhere, sometimes not all the cells in this range have a value, some are only "".

    Problem

    Suppose all cells in the range have numerical values, my array formula would be the following;

    {=mmult(transpose($A$2:$Z$100),$A$2:$Z$100))/(count($A$2:$A$100)-1)}

    However when the range is only partially ocupied with data, for example - it may only be cells A2 to D100 which contain values; this means I have to manually adjust the formula and change the cell range manually.

    Seeking Solution

    With your help, I am looking to create a formula which performs the same task as above but removes the need to change the cell ranges, I would like the new formula to ignore blanks and produce the same value answer automatically as it does when it is manually adjusted to fit the range. i.e. automatically calculate the formula function relevant to cells A2 : D100 but spanning the entire range of A2 : Z100 in case next time the data range spans further.

    Hopefully this is somewhat clear, I would be happy to produce any further explaination.

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Array Formula which ignores blank cells / only calculates cells with values

    persisting the A:Z approach then, perhaps, something like the below will address your null string issue:

    {=mmult(transpose(--(0&$A$2:$Z$100)),--(0&$A$2:$Z$100)))/(count($A$2:$A$100)-1)}

    alternatively, if your 'active' matrix (i.e. A:D rather than A:Z) would never store interspersed null strings then you might consider switching to a dynamic named range approach, e.g.:

    Name: =_Data
    RefersTo: =$A$2:INDEX($A:$Z,MATCH(9.99E+307,$A:$A),MATCH(9.99E+307,$2:$2))

    at which point your formula would become:

    {=mmult(transpose(_Data),_Data))/(count(index(_Data,0,1))-1)}
    Last edited by XLent; 07-22-2020 at 04:07 AM.

  3. #3
    Registered User
    Join Date
    05-22-2020
    Location
    Leningrad
    MS-Off Ver
    2007
    Posts
    34

    Re: Array Formula which ignores blank cells / only calculates cells with values

    This is definately moving in the right direction! It is much appreciated.
    I do have some questions;

    1. In _Data range, what is the significance of the +307 number? (Purely for my learning)

    (I have moved the table originally in A2:Z100 to B 1132 : ALM 1182
    2. I have inputted the formula but I must be going wrong with the syntax as it keeps returning "#REF" Could I ask you perhaps where I am going wrong? I have included the formula with updated location for reference;


    {=MMULT(TRANSPOSE($B$1132:INDEX($B:$ALM,MATCH(9.99E+307,$B:$B),MATCH(9.99E+307,$1132:$1132))),((($B$1132:INDEX($B:$ALM,MATCH(9.99E+307,$B:$B),MATCH(9.99E+307,$1132:$1132)))/COUNT(INDEX($B$1132:INDEX($B:$ALM,MATCH(9.99E+307,$B:$B),MATCH(9.99E+307,$1132:$1132)),0,1))-1)))}

    Much appreciated!

  4. #4
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Array Formula which ignores blank cells / only calculates cells with values

    So, firstly, if you go down this route I would certainly advocate creating a Named Range (_Data) to house the dynamic calc, rather than repeat the dynamic calcs in each part of your MMULT.

    w.r.t 9.99E+307 -- this is simply a very big (exponential) number, i.e. 9.99*10^307

    when used in "binary search" context - e.g

    =MATCH(9.99E+307,$A:$A)
    or
    =LOOKUP(9.99E+307,$A:$A)

    this can be used to isolate the last numeric value in a range - the first above would return the row in which it is found, the second would return the value itself

    if you're interested in how this works check out Jon von der Heyden's write up: http://excelevolution.com/lookups-un...rch-algorithm/
    (specifically: Dynamic Ranges with Binary Search)

    in terms of why you calc isn't working.... obviously doing this without data but, I can see a couple of issues, one definite - one potential:

    Issue 1 -- mismatched ranges:

    INDEX($B:$ALM,MATCH(9.99E+307,$B:$B),MATCH(9.99E+307,$1132:$1132))

    in the above your INDEX range should be $A:$ALM rather than $B:$ALM, this is because your "column" MATCH is referencing $1132:$1132 rather than $B$1132:$ALM$1132
    so, if the last number were in C, the MATCH would return 3, and the 3rd column of your current INDEX range is D, rather than C.... so you get a disjoin.

    that being said, given all elements have the same error, whilst this would certainly not generate the correct results I am not sure why you would get #REF!
    (does the column to the right of the last numeric column hold #REF! errors?)

    issue 2: change in approach?

    the construct of the latest formula does not mirror that of your initial post -- your initial post:

    =MMULT(Transpose(range),range)/(COUNT(range[column1])-1)

    whereas your latest has the divisor being applied against the 2nd range within the MMULT

    =MMULT(Transpose(range),range/(COUNT(range[column1])-1))

    Your latest formula, using the initial construct (and with issue 1 resolved), should read:

    {=MMULT(TRANSPOSE($B$1132:INDEX($A:$ALM,MATCH(9.99E+307,$B:$B),MATCH(9.99E+307,$1132:$1132))),$B$1132:INDEX($A:$ALM,MATCH(9.99E+307,$B:$B),MATCH(9.99E+307,$1132:$1132)))/(COUNT($B$1132:INDEX($B:$B,MATCH(9.99E+307,$B:$B)))-1)}

    but, just to reiterate, I would create the dynamic named range, and then use the approach outlined in post 2.
    Last edited by XLent; 07-23-2020 at 04:28 AM.

  5. #5
    Registered User
    Join Date
    05-22-2020
    Location
    Leningrad
    MS-Off Ver
    2007
    Posts
    34

    Re: Array Formula which ignores blank cells / only calculates cells with values

    Firstly XLent, I just want to say thank you for the great attention and knowledge you have shared with me so far, it is genuinely appreciated!

    I have been playing about with the formula for some time now. I have attempted the first recommendation of a named dynamic range, it did not provide a result. Secondly, I pasted the formula at the end of your answer but it returned the following,

    "Microsoft Excel cannot calculate a formula. There is a circular reference in an open workbook, but the references that cause it cannot be listed for you. Try editing the last formula you entered or removing it with the Undo command." It is also returning 0% values in every cell also.

    I have made a copy of the workbook, exactly replicated with unnecessary information redacted. The cell references are exactly replicated and with the formula in place; hopefully to diagnose where I have went wrong. Hope this adds some clarity.

    Again, your help is much appreciated!

    [link removed]
    Last edited by LordByron; 08-02-2020 at 06:47 AM.

  6. #6
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Array Formula which ignores blank cells / only calculates cells with values

    I'll happily look at the file but would ask you upload directly -- refer to the Yellow Banner at the top of the page re: "how to upload" (note: the paperclip icon does not work)

  7. #7
    Registered User
    Join Date
    05-22-2020
    Location
    Leningrad
    MS-Off Ver
    2007
    Posts
    34
    Much appreciated XLent however when I attempted to upload the file it was over the size limit for uploads. I compressed the file, still too big. Used zip folder, too large; the Dropbox link was the only method left that I was aware of. Do you know of any workarounds I could use to upload the file?
    Last edited by AliGW; 08-02-2020 at 06:46 AM. Reason: Please don't quote unnecessarily!

  8. #8
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Array Formula which ignores blank cells / only calculates cells with values

    You could try saving as .xlsb -- as this can offer the best compression, if it's still over 9.77MB then it will fail.

  9. #9
    Registered User
    Join Date
    05-22-2020
    Location
    Leningrad
    MS-Off Ver
    2007
    Posts
    34

    Re: Array Formula which ignores blank cells / only calculates cells with values

    Hi XLent, so far I have reduced the file size, saved it as XLSB and attempted upload. Unfortunately when attempting upload it is returning, 'Upload of file failed.' Any advice? Thanks

  10. #10
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Array Formula which ignores blank cells / only calculates cells with values

    Hi, for reference, I have attached the file - but have removed all bar one of the MMULTs

    So, the circular problem arose because the formula is, itself, located in Column B (which I wasn't aware of) - as a result, the MATCH (last number) formula became self-referencing

    What I am not sure I understand is how the MMULT is to change per cell in the matrix?
    Could you provide some expected results for say the first four cells (2x2) in the result matrix?
    (I suspect there is a tweak, or two, required here)

    note: in the attached I have inserted a named range which assumes that whilst the final column is unknown (B:ALM) the final row is fixed (1182)
    (we can modify if needed)
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    05-22-2020
    Location
    Leningrad
    MS-Off Ver
    2007
    Posts
    34

    Re: Array Formula which ignores blank cells / only calculates cells with values

    Hi XLent,

    I am still experiencing difficulties in uploading the workbook. We are definitely moving in the right direction! Much appreciated! The circular reference is now no longer a problem. I have attached the workbook with the first few values confirmed (manually). The first formula using your method corresponds with my manual formula so I assume everything is working well.

    The first x values in the table as as follows, in percentage terms,

    176, -30, -11, 2
    -30, 90, -15, -18
    -11, -15, 223, 18
    2, -18, 18, 138
    37, 1, -29, -61
    21, 10, -5, 2

    I will leave that with you for your consideration in case there are any tweaks which I have missed.

    Much appreciated!

  12. #12
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: Array Formula which ignores blank cells / only calculates cells with values

    OK; so it sounds as though you now have a working solution - which is good news.

    Post back if you encounter any other issues.

  13. #13
    Registered User
    Join Date
    05-22-2020
    Location
    Leningrad
    MS-Off Ver
    2007
    Posts
    34

    Re: Array Formula which ignores blank cells / only calculates cells with values

    Hi Xlent,

    I can confirm everything is working great! I was testing it on the required sheets, working perfectly! Thank you so much, you really helped me out! All the best!
    Last edited by AliGW; 08-02-2020 at 06:46 AM. Reason: Please don't quote unnecessarily!

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,406

    Re: Array Formula which ignores blank cells / only calculates cells with values

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. How to create a chart that ignores blank cells?
    By Mr.Castle in forum Excel General
    Replies: 4
    Last Post: 09-11-2018, 12:25 PM
  2. [SOLVED] Nested IF formula that ignores blank cells
    By si.mon in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-22-2018, 06:19 AM
  3. dynamic chart that ignores formula cells with no values.
    By LNLD in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-29-2016, 11:06 AM
  4. [SOLVED] Dynamic Range in Column Chart That Ignores Blank and With-Formula Cells
    By ykobure in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-26-2015, 08:57 AM
  5. Replies: 1
    Last Post: 12-20-2013, 12:49 PM
  6. Average formula that starts at first cell>0 and calculates blank cells as 0?
    By bradtredo in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-20-2012, 05:54 PM
  7. Replies: 2
    Last Post: 07-11-2012, 08:58 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