+ Reply to Thread
Results 1 to 7 of 7

Database queries in Excel

  1. #1
    Forum Contributor
    Join Date
    01-16-2019
    Location
    NY
    MS-Off Ver
    Office 365
    Posts
    120

    Database queries in Excel

    I have forgotten how to use querries on data in excel. I have an older file where i ran a bunch of querries to get summary stats. Now i replicated that same overall data with the newest information and i want to be able to pull similar summary stats. I remember you have to name the data - and i created a table name. Attached is just a sample of the data downloaded from online, there's actually thousands of rows in the real database. how do i run querries like what is hte market cap by country or how many stocks in each country - where it shows me summary tables.

    Second, if i have the old data, and i want to compare the two files -- how many US companies now versus 2019 -- how do i set that up in exce?
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: Database queries in Excel

    With Power Query, you can do Groups. This one counts stocks by country.

    Please Login or Register  to view this content.
    Sum of Market Values By Country

    Please Login or Register  to view this content.
    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: Database queries in Excel

    As to your second question. You can run joins to compare the data from old to new in Power Query. If you are new to Power Query, then you may wish to pick up Ken Puls Book on Power Query. Google Ken Puls and Power Query. The book is available on Amazon.

  4. #4
    Forum Contributor
    Join Date
    01-16-2019
    Location
    NY
    MS-Off Ver
    Office 365
    Posts
    120

    Re: Database queries in Excel

    Super helpful!!!
    1) Further quesiton: Instead of sum of market value by country, if i want the average market cap by country how do i change the code? would i just replace the list.Sum to List.Average?
    2) I added another column to the left of column E tha tsay tier where it brings back the first 5 letters of the word. How can i then get it to sort by the new column F by country and by market cap?
    3) How do i do these sorts wihtout the code becasue i'm pretty sure i didnt use the code back in 2019?
    4) Can you provide me informatino on the join feature - how do i compare the two data sets quickly?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,472

    Re: Database queries in Excel

    Formula for sales by country:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2016 & H&B2021
    Posts
    3,065

    Re: Database queries in Excel

    Alternatively, you can use PivotTable.
    Attached Files Attached Files

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,897

    Re: Database queries in Excel

    Market Cap Average by Country

    Please Login or Register  to view this content.
    To compare different years.

    Bring each file table into the Power Query Editor.

    Depending on what you wish to compare, you may want to group each of them separately and then merge them by joining them on a common(s) field. If you have a prior period you wish to demo and compare to the current one, you can upload and I will give it a shot for you. I would assume you wish to compare based upon the three criteria we have done for the current period.

+ 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. Writing queries in Excel based on fields from an external database
    By bscace in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2014, 04:27 PM
  2. Run Sql Queries in excel against database using Macro
    By Analabhatla in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-01-2014, 10:14 PM
  3. Can I use excel as a database with single-cell queries?
    By pine in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-19-2013, 10:28 PM
  4. Embedded Access queries in Excel - if the database moves, how to update queries?
    By Paul_mcc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-06-2012, 07:52 PM
  5. Execute multiple SQL queries on a specific oracle database and log results in excel
    By harsh2209 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-08-2012, 01:38 PM
  6. Replies: 2
    Last Post: 01-31-2012, 05:40 PM
  7. Executing queries stored in database in Excel
    By John B in forum Excel General
    Replies: 0
    Last Post: 12-15-2005, 05:15 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