+ Reply to Thread
Results 1 to 10 of 10

Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

  1. #1
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    Hi all,

    I've set up a sheet which copies filtered data from one table to the other using this macro:

    https://www.excelforum.com/excel-pro...ok-inside.html

    This source table is frequently cleared and new data is copied back in. That can be 30 rows or it can be 100+. It depends.

    I set up my bar charts to plot only the top 30 rows for each chart. So far, so good.

    The problem is that when clearing my table and copying in a new set of data, Excel by default extends the data range to include the entire table range and not the last 30 only.

    Uten navn.png

    Is there any remedy for this...?

    I use OFFSET functions a lot to calculate averages with dynamic lookback periods based on a cell value. If charts could easily be created using OFFSET, that could be some solution also. I tried entering my typical OFFSET formula directly into the data range, but no luck...

    I'm attaching the workbook for this.

    Thanks in advance.

    Best regards.
    Attached Files Attached Files

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    Hello,

    create range names that return the last 20 rows of your data dynamically, then plug the range names into the charts.

    Jon Peltier has a detailed step by step tutorial here

    https://peltiertech.com/Excel/Charts...tml#DynoLast12

    Pipe up if you need more help.

  3. #3
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    Hi, teylyn,

    Thank you!

    I'm slowly working through that now. It does seem a bit complex. I was hoping I could find some easier method as I have around 15 charts to set up this way. But maybe it's fast once I manage to pull of the first one.

    Best regards.

  4. #4
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    So, I tried that method:

    https://peltiertech.com/Excel/Charts/DynamicLast12.html

    I think maybe I was able to create the named ranges correctly.

    But, I can't seem to be able to create the chart...

    Attaching updated workbook.


    Maybe it will be easier when I understand it completely and one can use copy and paste, but I can't help wonder if there's an easier way to accomplish this? At least if I don't want a dynamic lookback period, but say fixed at 30 days? The reason being that I need to do this on a lot of charts...

    Thanks in advance for all help.

    Elijah
    Attached Files Attached Files
    Last edited by Elijah; 01-20-2019 at 04:59 PM.

  5. #5
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    Hello,

    you have successfully created the three range names and they point to the last 30 rows of your data. You don't seem to have a range name for the chart axis, though. Which column do you want to show in the axis?

    I typically create the first range name on the column for the chart labels, which in most cases is to the left of the numbers, then use a simple offset from the labels column to the data series columns.

    Then create a chart of your choice and replace the Axis labels range and the Series range definitions with the range names.

    I guess you want the Date as the chart axis, so you can create a name "chtLabels" with the formula

    =OFFSET(chtCats,0,-15)

    When you edit the chart source to put in the range names, you need to enter the range names preceded by a sheet name. So, type
    =FilteredData!chtLabels for the chart labels and =FilteredData!chtCats for the series in column Q.

    For some reason, the range names chtValA and chtValB throw errors when I try to put them into the chart. I renamed them to chtSeriesA and chtSeriesB and now it works. See attached.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    Hey, teylyn,

    Great! Thanks a lot!

    Quote Originally Posted by teylyn View Post
    Hello,

    you have successfully created the three range names and they point to the last 30 rows of your data. You don't seem to have a range name for the chart axis, though. Which column do you want to show in the axis?
    I don't really need an axis, although date is okay.

    When I created this chart originally, I just selected the data in the column and it returned 1, 2, 3, 4, ... etc on the axis. That's okay for me.

    However, it shouldn't be the LAST 30 rows of data, but the FIRST 30 rows of data. Meaning row 7 to 36.

    Maybe my English could be better as I used both the word "Last" and also "Top 30" rows. But I meant top rows...

    My data sheet is updated at the top so I'm basically interested in the newest data which starts from the top. So it should be the other way around than it is now.

    Can you help?

    Quote Originally Posted by teylyn View Post
    Which column do you want to show in the axis?
    I'm basically interested in creating charts for almost all column listed there, but I want one column per chart only. So basically 10 charts or so. But it will be in another workbook. This one is just for testing.

    Quote Originally Posted by teylyn View Post
    For some reason, the range names chtValA and chtValB throw errors when I try to put them into the chart. I renamed them to chtSeriesA and chtSeriesB and now it works. See attached.
    That was where I got errors also, I think. Did you only change the range name? Formula was okay?

    Thanks again.

    Elijah
    Last edited by Elijah; 01-20-2019 at 06:13 PM.

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    Hi,

    I only changed the range names, not the formulas. Adding new data at the top is unusual and might create problems with formulas. But if you want to do it that way, the range name formula will be very easy. Understand how Offset works

    =Offset(startrange,row offset, column offset, height, width)

    If you want to plot from row 2 to row 32, the you can use

    =Offset(A1,1,0,30,1)

    In words: Starting from A1, go 1 row down, stay in the same column, include 30 rows and 1 column wide.

  8. #8
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    Hi,

    Thank you!


    This OFFSET formula you're typing above would also have to be associated with a named range, right? And I could still use a cell value instead of 30?

    I'm very familiar with using OFFSET on my statistical formulas such as average, maximum, minimum, etc. I have just not used them for charts.

    Anyway, I just tried to do this before heading to work, but no luck actually creating the chart...

    I created a named range "Close_PL" which would refer to the column with header "Close_PL". I used formula OFFSET(FilteredData!$S$7;1;0;30;1). I assume 30 could be swapped with cell O1 to make it 'dynamic'.

    I get an error for circle references when trying to add the series to the chart you made.

    Uten navn.png

    Thanks in advance for all help!
    Attached Files Attached Files
    Last edited by AliGW; 01-21-2019 at 02:14 AM.

  9. #9
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    That's strange. A single offset formula should not return a circular reference warning, ever. And I've never seen a circular reference warning when a range name is applied to a chart. The only error that can come up is that there is an invalid range, but not a circular reference in the named range.

    Anyway I copied and pasted your Offset formula into a named range "Close_PL". No warning.

    I added a series to the chart with that named range. No error, no warning.

    see attached.
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Set up a bar chart to always show only the last 20 rows? Alternatively OFFSET?

    Hi, teylyn,

    Thank you very much! I have now set up all my charts using this method. It didn't take much time when I had the general formula and procedure figured out. IMO, Excel should offer this as an inbuilt possibillity, but I suppose that will be so sometime in the future.

    Thank you!

    Elijah

+ 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. Replies: 12
    Last Post: 10-10-2018, 12:43 PM
  2. Using a Listbox in order to show more rows in a chart.
    By olaus in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-16-2015, 05:53 AM
  3. Replies: 3
    Last Post: 04-12-2013, 04:36 PM
  4. Not Show Hidden Rows in Column Chart?
    By DCSwearingen in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 06-10-2008, 09:37 AM
  5. Insert rows alternatively in Pivot Table to calculate percentage of fixed ranges
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2008, 12:19 PM
  6. Delete Rows based on cell value and then Insert rows alternatively with a formula
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-11-2008, 04:27 PM
  7. Show hidden rows in chart?
    By a94andwi in forum Excel General
    Replies: 3
    Last Post: 03-02-2007, 11:19 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