21
Excel Dynamic Named Ranges (w/ Tables) = Chart Automation Published by Tim Wilson on June 8, 2013All posts from Tim Wilson The single post on this blog that has, for several years now, consistently driven the most traffic to this site, is this one that I wrote almost three years ago. Apparently, through sheer volume of content on the page and some dumb luck with the post title, I consistently do well for searches for “Excel dynamic named ranges” (long live the long tail of SEO!). The kicker is that I wrote that post before I’d discovered the awesomeness of Excel tables , and before Excel 2010 had really gone mainstream. I’ve been meaning to redo the original post with an example that uses tables, because it simplifies things a bit. This is that post — 100% plagiarized from the original when it makes sense to do so. The content was created in Excel 2010 for Windows. However, it should work fine on Excel 2007 for Windows, too. Macs are a bit of a crap shoot, unfortunately (but you can always run Parallels , so I hear, and use Excel for Windows!). This post describes (and includes a downloadable file of the example ) a technique that I’ve used extensively to make short work of updating recurring reports. Here are the criteria I was working against when I initially implemented this approach: User-selectable report date User-selectable range of data to include in the chart Single date/range selection to update multiple charts at once No need to touch the chart itself Reporting of the most recent value (think sparklines, where you want to show the last x data values in a small chart, and then report the last value explicitly as a number) No use of third-party plug-ins

Excel Dynamic Named Ranges.docx

Embed Size (px)

Citation preview

Excel Dynamic Named Ranges (w/ Tables) = Chart AutomationPublished by Tim Wilson on June 8, 2013All posts from Tim WilsonThe single post on this blog that has, for several years no, !onsistently driven the mosttraffi! to this site, is this onethat " rote almost three years ago# Apparently, through sheer volume of !ontent on the page and some dumb lu!$ ith the post title, " !onsistently do ell for sear!hes for %&'!el dynami! named ranges( )long live the long tail of *&+,-#The $i!$er is that " rote that post before ".d dis!overed the aesomeness of &'!el tables, and before &'!el 2010 had really gone mainstream# ".ve been meaning to redo the original post ith an e'ample that uses tables, be!ause it simplifies things a bit#This is that post / 1000 plagiari1ed from the original hen it ma$es sense to do so# The !ontent as !reated in &'!el 2010 for Windos# 2oever, it should or$ fine on &'!el 2003 for Windos, too# 4a!s are a bit of a !rap shoot, unfortunately )but you !an alays run Parallels, so " hear, and use &'!el for Windos,-#This post des!ribes )and in!ludes a donloadable file of the e'ample- a te!hni5ue that ".ve used e'tensively to ma$e short or$ of updating re!urring reports# 2ere are the !riteria " as or$ing against hen " initially implemented this approa!h6 7ser8sele!table report date 7ser8sele!table range of data to in!lude in the !hart *ingle date9range sele!tion to update multiple !harts at on!e :o need to tou!h the !hart itself ;eporting of the most re!ent value )thin$ spar$lines, here you ant to sho the last x data values in a small !hart, and then report the last value e'pli!itly as a number- :o use of third8party plug8ins :o ma!ros / " don.t have anything against ma!ros, but they introdu!e priva!y !on!erns, version !ompatibility, odd little arnings, and, in this !ase, aren.t neededThe e'ample shon here is pretty basi!, but the approa!h s!ales really ell#*ound li$e funirst, the report period# Fli!$ in !ell F1, sele!t Data * Data 1alidation, !hoose 2ist, andthen referen!e the first !olumn in the +ain,Data table )see the %;eferen!ing Tables andParts of Tables( se!tion in this post for an e'planation of the spe!ifi! synta' used here, in!luding the use of the!ND!RECT fun!tion-6When you !li!$ -3, you ill have a dropdon in !ell F1 that !ontains all of the availablemonths# This is a !riti!al !ell / it.s hat e.ll use to sele!t the date e ant to $ey off offor reporting, and it.s hat e.ll use to loo$ up the data# *o, e need to ma$e it a named !ell / Re4ort$eriod6:o, let.s do a similar operation for the report range / this tells the spreadsheet ho many months to in!lude in ea!h !hart# Fli!$ in !ell F3, sele!t Data * Data 1alidation, !hoose 2ist, and then enter the different values you ant as options )".ve used 3, J, B, and 12 here, but any list of integers ill or$-6And, let.s name that !ell Re4ortRange6Aoes this seem li$e a lot of or$< "t !an be a bit of a hassle on the initial setup, but it ill pay huge dividends as the report gets updated ea!h day, ee$, or month# Trust me,Eefore e leave this tab, go ahead and sele!t a value in ea!h dropdon / this ill ma$e it easier to !he!$ the formulas in the ne't step#DATA TA& ET#$ ( $ART 5:o is here the fun begins# We.re going to go ba!$ over to the Data or$sheet and start setting up some additional named ranges# We.ve got +ain,Data, hi!h is the table that in!ludes the full range of data# We ant to loo$ at the !urrently sele!ted Re4ort $eriod )a named range !alled Re4ort$eriod- and find the value for ea!h metri! that is in the same ro as that report period# That ill give us the %Furrent( value for ea!h metri!# All you need to do is put theexact same formula in ea!h of the three %Furrent( !ells6K@?++L7P);eportPeriod,4ainDAata,F+?74:)--"n this e'ample, these are the values for ea!h of the three arguments6 Re4ort$eriod G Jul812, the value e sele!ted on the Dashboard tab +ain,Data / this is the full table of data C-2#+N() / this is 2, the !olumn that the !urrent metri! is listed in )this fun!tion resolves to %3C for -rders and to %MC for /eb Tra00ic )Note' "f you have additional !olumns in your data sheet, you may have to ma$e this %F+?74:)-8#( "f, for instan!e, you have a blan$ !olumn A before the table starts to provide some spa!e, you ould use %F+?74:)-81#( This applies to other uses of F+?74:)-throughout this post#-*o, the formula simply ta$es the !urrently sele!ted month, finds the ro ith that value in the data array, and then moves over to the !olumn that mat!hes the !urrent !olumn of the formula6*li!$, huh< And, be!ause the Re4ort$eriod data validation dropdon on the Dashboard or$sheet is referen!ing thefirst column of the data table on the Data tab, the @?++L7P ill alays be able to find a mat!hing value# );ead that last senten!e again if it didn.t sin$ in / it.s a nifty little ay of ensuring the robustness ofthe report-This little bit of !leverness is really =ust a setup for the ne't step, hi!h is setting up the data ranges that e.re going to !hart# Fon!eptually, it.s very similar to hat e did to find the !urrent metri! value, but e ant to sele!t the range of data that ends ith that value and goes backwards by the number of months spe!ified by Re4ortRange# *o, in the values e sele!ted above, Jul80B and %J,( e basi!ally ant to be able to !hart the folloing range of data6We.ll do this by defining a named range !alled Re.enue,Range )note ho this has a similar naming !onvention toRe.enue,Current, the name e gave the !ell ith the single value / this !omes in handy for $eeping tra!$ of things hen setting up the dashboard-# We !an.t use @?++L7P, be!ause that fun!tion doesn.t really or$ ith arrays and ranges of data# "nstead, e.ll use a !ombination of the 4ATF2 fun!tion )hi!h is sort of li$e @?++L7P on steroids- and the ":A&N fun!tion )hi!h is a handy ay to grab a range of !ells-# Pull your hat don and fasten your seatbelt, as this one gets a little s!ary# 7ltimately, the formula loo$s li$e this6K":A&N)4ainDAata,4ATF2);eportPeriod,4ainDAataO;eport PeriodP-8;eport;angeQ1, F+?74:);evenueDFurrent--6":A&N)4ainDAata, 4ATF2);eportPeriod,4ainDAataO;eport PeriodP-, F+?74:);evenueDFurrent--"t.s really not that bad hen you brea$ it don# " promise,Wor$ing from the outside in, you.ve got a !ouple of ":A&N)- fun!tions# Thin$ of those asbeing ":A&N)>irst Fell- and ":A&N)?ast Fell-#The range is defined, in pseudo!ode, as simply6K":A&N)>irst Fell-6":A&N)?ast Fell-The ?ast Fell !al!ulation is slightly simpler to understand# As a matter of fa!t, this is really =ust trying to identify the cell location )not the value in the !ell- of the !urrent value for revenue / very similar to hat e did ith the @?++L7P fun!tion earlier# The ":A&N fun!tion has three arguments6 ":A&N)array,roDnum,!olumnDnum-# 2ere.s ho those are getting populated6 array / this is simply set to +ain,Data, the full data table row,num / this is the ro number within the array that e ant to useR e.ll !ome ba!$ to that in =ust a minute column,num / e use a similar tri!$ that e used on the Re.enue,Current fun!tion, in that e use the F+?74:)- formulaR but, sin!e e set up this range simply as a named range )as opposed to being a value in a !ell-, e !an.t leave the value of the fun!tion blan$R so, e populate the fun!tion iththe argument of Re.enue,Current / e ant to grab the !olumn that is the same !olumn as here the !urrent revenue value is populated in the top ro#:o, ba!$ to ho e determine the row,num value# We do this using the 4ATF2 fun!tion, hi!h e need to use on a 18dimensional array rather than a 28dimensional array )+ain,Data is a multi8!olumn table, hi!h ma$es it a28dimensional array-# All eant this fun!tion to return is the number of the ro in the +ain,Data table for the !urrently sele!ted report period, hi!h, as it turns out, is the same ro as the !urrently sele!ted report period in the first !olumn )%;eport Period(-# The formula is pretty simple64ATF2);eportPeriod,4ainDAataO;eport PeriodP-The formula loo$s in the first !olumn of the +ain,Data table for the Re4ort$eriod valueand finds itIin the seventh ro of the table# *o, row,num is set to 3#":A&N)>irst Fell- is almost identi!al to ":A&N)?ast Fell-, e'!ept the row,num value needs to be set to 2 instead of 3 / that ill ma$e the full range mat!h the Re4ortRange value of J# *o, row,num is !al!ulated as6MATCH!eport"eriod#Main$%ata&!eport "eriod'()!eport!ange*+)The %Q1C is needed be!ause e ant the total number of !ells in!luded in the range to be Re4ortRange in!lusive#-:o, that.s not all that s!ary, is it< We =ust need to drop the full formula into a named range !alled Re.enue,Range by sele!ting 6ormulas * Name +anager * New, naming the range Re.enue,Range, and inserting the formula6K":A&N)4ainDAata,4ATF2);eportPeriod,4ainDAataO;eport PeriodP-8;eport;angeQ1, F+?74:);evenueDFurrent--6":A&N)4ainDAata, 4ATF2);eportPeriod,4ainDAataO;eport PeriodP-, F+?74:);evenueDFurrent--The hole formula is there, even if you !an.t see it,;epeat this last step to !reate to more named ranges ith slightly different formulas )the differen!es are in bold-6 -rders,Range' K":A&N)4ainDAata,4ATF2);eportPeriod,4ainDAataO;eport PeriodP-8;eport;angeQ1, F+?74:)+rdersDFurrent--6":A&N)4ainDAata, 4ATF2);eportPeriod,4ainDAataO;eport PeriodP-, F+?74:)+rdersDFurrent-- /ebTra00ic,Range' K":A&N)4ainDAata,4ATF2);eportPeriod,4ainDAataO;eport PeriodP-8;eport;angeQ1, F+?74:)WebTraffi!DFurrent--6":A&N)4ainDAata, 4ATF2);eportPeriod,4ainDAataO;eport PeriodP-, F+?74:)WebTraffi!DFurrent--Ti4' After !reating one of these named ranges, hile still in the :ame 4anager, you !ansele!t the range and !li!$ into the formula bo', and the !urrent range of !ells defined bythe formula ill sho up ith a blin$ing dotted line around them#Sou.re getting sooooooo !lose, so hang in there, "n order for the !hart labels to sho up !orre!tly, e need to ma$eone more named range# We.ll !all it Date,Range and define it ith the folloing formula )this is =ust li$e the earlier,Range formulas, but e $no eant to pull the dates from the first !olumn, so, rather than using the F+?74:)- formula, e simply use a !onstant, %1C6K":A&N)4ainDAata,4ATF2);eportPeriod,4ainDAataO;eport PeriodP-8;eport;angeQ1,1-6":A&N)4ainDAata, 4ATF2);eportPeriod,4ainDAataO;eport PeriodP-,1-"f you ant, you !an fiddle around ith the different settings on the Dashboard tab and at!h ho both the %Furrent( values and )if you get into :ame 4anager- the ,Range areas !hange#+;Iyou !an move on to the final step, here it all !omes together,DA%&-ARD TA& ET#$ ( $ART 5 (T%E 6!NA2 TE$)"t.s ba!$ over to the Dashboard or$sheet to rap things up#"nsert a 28A ?ine !hart and resi1e it to be less than totally obno'ious# "t ill =ust be a blan$ bo' initially6;ight8!li!$ on the !hart and sele!t elect Data# Fli!$ to Add a ne series and enter %;evenue( )ithout the 5uotes / &'!el ill add those for you- as the series name and the folloing formula for the series values6KAynami!FhartsWithTablesD&'ample#'ls',;evenueD;ange)Fhange the name of the or$boo$ if that.s not hat your or$boo$ is named)Fli!$ to edit the a'is labels and enter a similar formula6KAynami!FhartsWithTablesD&'ample#'ls',AateD;angeSou ill no have an absolutely horrid loo$ing !hart )than$ you, &'!el,-6Tighten it up ith some level of formatting )if you =ust !an.t stand to ait, you !an go ahead and start flipping the dropdons to different settings-, drop %K;eportPeriod( into !ell &J and %K;evenueDFurrent( into !ell &3, and you ill ind up ith something that loo$s li$e this6+$ay, so that still loo$s pretty horridIbut this isn.t a post about data visuali1ation, and ".m trying to ma$e the e'ample as illustrative as possible# "n pra!ti!e, e use this te!hni5ue to populate a sle of spar$lines )no '8a'is labels- and a !ouple of bar !harts, as ell as some additional !al!ulated values for ea!h metri!#To add !harts for orders and eb traffi! is a little easier than !reating the initial !hart# Just !opy the ;evenue !hart a !ouple of times )if you hold don TFtrlH8T*hiftH and then !li!$ and drag the !hart it ill ma$e a !opy and $eep that !opy aligned ith the original !hart-#Then, simply !li!$ on the data line in the !hart and loo$ up at the formula bo'# Sou ill see a formula that loo$s something li$e this6K*&;"&*)%Re.enue%,Aynami!FhartsWithTablesD&'ample#'ls',AateD;ange, Aynami!FhartsD&'ampleWithTables#'ls',Re.enueD;ange,1-Fhange the bolded te't, %;evenue,( to be %+rders( and the !hart ill update#;epeat for a Web Traffi! !hart, and you.ll ind up ith something li$e this6AndIfor the magi!ITdrum rollllllllllllHFhange the dropdons and at!h the !harts update,*o, is it orth it< :ot if you.re going to produ!e one report a !ouple of times and move on# Eut, if you.re in a situation here you have a lot of re!urring, standardi1ed reports )not as mindless report mon$eys / these should be ell8stru!tured, ell8validated, a!tionable performan!e measurement tools-, then the payoff ill hit pretty 5ui!$ly# 7pdating the report is simply a matter of updating the data on the Data tab )some of hi!h !an even be done automati!ally, depending on the data sour!e and the AP" availability-, then the Re4ort $eriod dropdon on the Dashboard tab !an be !hanged to the ne report period, and the !harts get automati!ally updated, Sou !an then spend your time analy1ing and interpreting the results# +ften, this means going ba!$ and digging for more data to supplement the reportIbut ".m teetering on the verge of mu!h larger topi!, so ".ll stopIAs an added bonus, you !an hide the Data tab and distribute the spreadsheet itself, enabling your end users to flip ba!$ and forth beteen different date ranges / a poor man.s E" tool, if ever there as one )in pra!ti!e, there ill seldom be any real insight gleaned from this limited number of ad=ustable dropdons, and that.s not the reason to set them up in the first pla!e-#" as !urious as to hat it ould ta$e to !reate this e'ample from s!rat!h and do!umentit as " ent# As it.s turned out, this is a lonnnnnnngggg post# Eut, if you.ve s$immed it, get the gist, and ant to start fiddling around ith the e'ample used here, feel free to donload it,2appy dynami! !harting,