简体   繁体   中英

Creating an Excel Chart with Dynamic Dates that Come from a Drop Down Menu

I'm trying create a line graph where I can use a drop down to select the start and end dates (and the data seen will change dynamically to reflect those dates). Currently, my data looks like this:

 Date    (Total Funding Before) (Total Funding During) (Total Funding After)
 8/2017    150                          160                  150
 9/2017    160                          160                  160
 10/2017   170                          170                  150
 11/2017   180                          180                  170
 12/2017   190                          180                  160

Can anyone give me insight on how to create this?

Yes it's possible :D.

With some dynamic ranges and a lot of patience you could create something like this result:

在此处输入图片说明

Step-by-Step guide:

First we make the whole table into "Excel Table". Go to "Home" -> "Format as Table".

在此处输入图片说明

Next part, we need to create a couple of "Named Ranges". Go to: "Formulas" -> "Name Manager" -> "New..."

在此处输入图片说明

We make our start date a "Named Range". I name it to "Start_Date". And it refers to cell $B$3 . My Sheet name is "Sheet1".

We do exactly the same for the "End_Date. We refer it to the cell below, $B$4.

在此处输入图片说明

Then we create a name range for the "Date" column. We name our range to " Dates ". Check that the "Refers to:" is in this format "= TableX[Column Name] ". In our case =Table1[Date] . Notice that the name manager don't use "B7:B16", rather is a reference to the table column area. The last step is very important! , since we want to make all references dynamic.

在此处输入图片说明

Time to create drop-down list for start and end date.

Go to: "Data" -> "Data Validation" -> Choose: "List" -> "Source:" =Dates , which is our range we named in the previous step.

在此处输入图片说明

Time to create the dynamic range for the X-Axis. I name it " XAxis "

=OFFSET(Sheet1!$B$7,MATCH(Start_Date,Dates,0)-1,0, MATCH(End_Date,Dates,0)- MATCH(Start_Date,Dates,0)+1,1)

This formula will search where the first row is for the first date ( Start_Date ). Then it will see where the end date is located ( End_Date ). Those two together will create the range we need. I have " ; " as delimiter, while US have " , ".

在此处输入图片说明

Now we create all the Y-ranges we need. One for every series we want to plot.

We start with Column "Total Funding Before". I name it: YTotalFundingBefore and apply the following formula.

=OFFSET(XAxis,0,1)

So we use the same range as the XAxis and offset it by one column to the right.

在此处输入图片说明

We do the same for the following two Series.

Notice for every new serie we create a Name range, we change the column offset. So the last series I named to " YTotalFundingAfter " and the formula is almost same, except 3 .

=OFFSET(XAxis,0,3)

在此处输入图片说明

Time to apply these ranges for the graph. I select the whole table and create a Line Graph. Then I select the first chart-serie: "Total Funding Before". In the formula bar (marked yellow in the picture) I need to change my references.

在此处输入图片说明

Here I want to give a trick to save some time.

When I rewrite the formulas I start like this... since the named ranges will come up automatically (as you can see in the picture):

=SERIES(Sheet1!$C$6,Xaxis,YTotalFundingBefore,1)

在此处输入图片说明

Then I add the Sheet name in front of all the variables. In my case "Sheet1". Complete formula will be:

=SERIES(Sheet1!$C$6,Sheet1!Xaxis,Sheet1!YTotalFundingBefore,1)
=SERIES(HeaderCell , XAxis Range , Y-Axis Range , Serie Number)

And then we press enter.

在此处输入图片说明

Same thing for the other series, so the second one will be:

=SERIES(Sheet1!$D$6,Sheet1!Xaxis,Sheet1!YTotalFundingDuring,2)

在此处输入图片说明

And the same thing for the last serie. Notice I change the header cell ($E$6) and serienumber ( 3 ):

=SERIES(Sheet1!$E$6,Sheet1!Xaxis,Sheet1!YTotalFundingAfter,3)

在此处输入图片说明

Finally we have a dynamic graph based on our Start and End Date values.

The good thing with table is when new rows (dates) are added, the ranges will pick them up automatically and also the drop down-lists. In the picture below I added 2 rows for demonstration purpose.

在此处输入图片说明

There are one important drawback with this setup. When a user applies the whole first date in the date range (2017-08) AND the last date in the date range 2018-07, the chart-series will remove the name ranges and go to absolute values like this: ( =SERIES(Sheet1!$E$6,Sheet1!$B$7:$B$18,Sheet1!$C$7:$C$18,1) ). My solution have been to have a one or two extra dates in the beginning of the date range. Dates we will probably never use and therefore never use the complete date range.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM