+ Reply to Thread
Results 1 to 13 of 13

mysql connection

  1. #1
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    mysql connection

    Is it possible to create a real-time connection between excel and mysql?

    The mysql database updates about with new information about once an hour.

    What I want to build is a table which has about 50 rows, with the most recent data at the top and the oldest at the bottom.
    The entire table is dynamic, so it "rolls" through the data.

    We then would want other parts of the workbook to refer to the data and perform calculations on a periodic basis.

    I'll appreciate advice and thoughts on this project. (for example... I assume it would require VBA, and perhaps an addin such as the one here: https://www.mysql.com/why-mysql/windows/excel/ )

    I can upload a template with notes if this helps.

    Thank you!

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: mysql connection

    If you can set up the MYSQL database as an ODBC connection (do a web search for this), then you can use MS-Query to import the data. No VBA would be required for this part. Develop the SQL you want in some tool other than MS-Query. I'm a big fan of the tool, but admit that the query builder is painful to use and that's a kind assessment.

    I'm a bit hazy on what you want to do with the rolling part. You can set up the SQL to read in everything that has come in since the last update and sort by time descending.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: mysql connection

    thank you dflak. I'll search for the ODBC connection.

    As for the rolling part, yes, I just mean sorting... but in real time, automatically.

    So assuming there are only two columns in the EA (date, and value) then the date/value in row 2 at 10:46 AM would move to row 3 when the data query fetches a new date/value at 10:47. Same all the way down for 50 rows. After the 50th row, the data disappears forever!

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: mysql connection

    Another method would be to import the data after a certain time one hour ago, two hours ago, whatever to assure you get at least 50 rows. Then you can use a pivot table against the imported data with a date sort descending and a filter for the top 50. The pivot table might be useful for some of your analysis. The pivot table should return a fixed range of cells for any formulas you will use.

  5. #5
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: mysql connection

    Thank you dflak. I've tried pivot tables before but I'm not expert with them. Can formulas be run on them just as with an ordinary "flat" table in excel?

    Thanks!

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: mysql connection

    You can run formulas on pivot tables, but you have to "overlay" them with named dynamic ranges. Sometimes, especially if you are consolidating a lot of data, this is worth doing.

    However, I get the impression your requirement isn't like that. If you are going to go through that much trouble, you might as well make named ranges for the first 50 rows of the returned data.

    Here is a wiki on named ranges: http://www.utteraccess.com/wiki/Offs...Dynamic_Ranges

    Attached is a sample workbook to give you an idea how this might be implemented.

    Sheet1 has data returned from the query. In this case 98 rows. We only want to look at the latest 50. The query had a SORT BY clause of Sort By 1, desc so the dates come out newest to oldest.

    I defined a range called My_Date to overlay on the date: =OFFSET(Sheet1!$A$2 ,0 ,0, 50 ,1)

    This range points to Cell A2, goes zero rows down, zero columns to the right, and returns a range 50 rows deep and 1 column wide. Normally some of these parameters are calculated with CountA or maybe even Match.

    Once we define a range we can define other ranges from it. The name Value_2 =OFFSET(My_Date,0,1) which says, give me the same range as My_Date, but shifted by zero columns down and one column to the right.

    So My_Date points to A2:A51 and my Value points to B2:B51.

    I tried defining a range intersecting the table with rows 1:51, but I could not address it like a table. So it looks like individual named ranges are the only way to go.



    If you don't have a lot of columns or if you only need to reference a few of them, this approach may work for you.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: mysql connection

    Thank you! Very cool. I'll try running some formulas based on the ranges you put in. (and yes, the table will only have a few columns. Maybe no more than 5.)

    I'll study the wiki. For the pivot table, would I need a macro to tell it to "delete" the bottom x rows? If I don't delete them, and I'm checking the data 1 x/ per minute, then the workbook would build up 86,000 rows a day, ultimately slowing it down.

    Thanks

  8. #8
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: mysql connection

    If you use the pivot table approach, sort the date newest to oldest and there is a filter you can apply for Top 10 - except that you can specify top 50.

    [Edit] I lied. You can only do top 50 in a pivot table on something in the value field not on something in the row field. Forget about the pivot table approach altogether.

    Limit the amount of data coming in with the query, (you can pass a parameter with MS-Query) and then fine tune it with the named ranges.
    Last edited by dflak; 12-14-2017 at 06:10 PM.

  9. #9
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: mysql connection

    OK great, thanks so much for your help. I'm going to leave this thread open for a while in case anyone else has more info on the MySql connection. (But yes, I'm also going to study the ODBC and MS-Query.)

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: mysql connection

    This isn't the greatest wiki I've ever written, but it should get you started with MS-Query.

    http://www.utteraccess.com/wiki/MS_Query

  11. #11
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: mysql connection

    OK thanks. I'll go through that as well.

  12. #12
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: mysql connection

    Hi, I discovered today that the latest version of Excel Business Premium Pro (build 1711) has a different layout and I think more features than the earlier versions. Do you have it? It looks like it has lots of query functions built in. (and the layout is different... see attached screen shot). Let me know if you think this makes a difference. Thanks!
    Attached Images Attached Images

  13. #13
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: mysql connection

    I do not have it. good for you if it works.

+ 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: 0
    Last Post: 07-13-2017, 04:58 AM
  2. MySQL connection problems
    By pjwhitfield in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-27-2016, 03:16 AM
  3. MySQL Query from Existing Database Connection
    By manofcheese in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2015, 04:33 PM
  4. Connection between Excel and MySql Workbench
    By joseto_caviedes in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-12-2014, 09:08 AM
  5. Cube Analysis - MySQL Connection
    By gatornation in forum Excel General
    Replies: 0
    Last Post: 04-30-2007, 10:41 AM
  6. calling all pro's!!! macro that can modify dates in odbc connection to mysql
    By majestik in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-10-2005, 03:05 PM
  7. [SOLVED] connection to internet mysql-database
    By masterphilch in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-02-2005, 03:06 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