{"id":22072,"date":"2020-03-05T17:27:08","date_gmt":"2020-03-05T22:27:08","guid":{"rendered":"https:\/\/breakingintowallstreet.com\/biws\/?post_type=biws_kb&#038;p=22072"},"modified":"2024-08-14T06:36:56","modified_gmt":"2024-08-14T11:36:56","slug":"excel-database-functions","status":"publish","type":"biws_kb","link":"https:\/\/breakingintowallstreet.com\/kb\/excel\/excel-database-functions\/","title":{"rendered":"Excel Database Functions: How to Use Them [Tutorial Video] (21:22)"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-flat ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Excel Database Functions: How to Use Them<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/breakingintowallstreet.com\/kb\/excel\/excel-database-functions\/#Excel_database_functions\">Excel database functions<\/a><\/li><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/breakingintowallstreet.com\/kb\/excel\/excel-database-functions\/#How_Database_Functions_Work\">How Database Functions Work<\/a><\/li><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/breakingintowallstreet.com\/kb\/excel\/excel-database-functions\/#The_Most_Common_Functions\">The Most Common Functions<\/a><\/li><li class='ez-toc-page-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/breakingintowallstreet.com\/kb\/excel\/excel-database-functions\/#Excel_Database_Functions_Multiple_Criteria\">Excel Database Functions Multiple Criteria<\/a><\/li><\/ul><\/nav><\/div>\n\n<h2><span class=\"ez-toc-section\" id=\"Excel_database_functions\"><\/span>Excel database functions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Excel database functions fix some, but not all, of the problems with long SUMIFS and SUMPRODUCT formulas.<\/p>\n<p>For example, formulas that use SUMIFS and SUMPRODUCT are often difficult to enter and understand, sometimes dates don\u2019t work correctly, and it\u2019s difficult to set up criteria such as orders that match a certain date range AND a certain Sales Rep but NOT a certain industry.<\/p>\n<blockquote><p><strong>Excel Database Functions Definition:<\/strong> Excel database functions allow you to sum and count data in spreadsheets based on AND and OR conditions that join together multiple sets of criteria, such as dates, amounts, geographies, industries, and product identifiers.<\/p><\/blockquote>\n<p>Database functions do require more time to set up because you must create extra rows in the spreadsheet, and you must get the syntax <em>exactly right<\/em>, or nothing will work.<\/p>\n<p>A basic Database function setup might look like this:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-22242 size-full\" title=\"Excel Database Functions - Example\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075454\/Excel-Database-Functions-01-1.jpg\" alt=\"Excel Database Functions - Example\" width=\"1017\" height=\"328\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075454\/Excel-Database-Functions-01-1.jpg 1017w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075454\/Excel-Database-Functions-01-1-300x97.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075454\/Excel-Database-Functions-01-1-768x248.jpg 768w\" sizes=\"(max-width: 1017px) 100vw, 1017px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Some of the key Excel database functions include the following:<\/p>\n<p><strong>=DSUM:<\/strong> Add numbers in a field (i.e., table column) that match specific conditions<\/p>\n<p><strong>=DCOUNT:<\/strong> Count # cells in a field (i.e., a table column) that match specific conditions<\/p>\n<p><strong>=DCOUNTA:<\/strong> Same, but only for nonblank cells<\/p>\n<p><strong>=DGET:<\/strong> Extracts single row from table that matches specific conditions<\/p>\n<div class='code-block code-block-4' style='margin: 8px 0; clear: both;'>\n<div class=\"kb-adinsert-modal\">\n    <div class=\"kb-adinsert-top\">\n      <div class=\"media\">\n          <img decoding=\"async\" class=\"alignnone size-full wp-image-28448\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2024\/05\/07054849\/Excel-VBA-Ico.png\" alt=\"Excel & VBA\" width=\"128\" height=\"128\" \/>\n      <\/div>\n      <div class=\"content\">\n          <h3>Learn Excel Shortcuts, Formulas, Graphs, Data, and VBA for Automation<\/h3>\n      <\/div>\n    <\/div>\n    \n    <div class=\"full_text\">\n    \t<ul>\n        \t<li>\n            \t<h4>Become a shortcut, formula & formatting machine<\/h4>\n              <p>Excel will be your \u201cnative language\u201d after you finish this course<\/p>\n\t\t\t    <\/li>\n          <li>\n          \t<h4>Learn the skills with dozens of practice exercises<\/h4>\n            <p>Learn by doing and check your work against the solutions<\/p>\n\t\t\t    <\/li>\n          <li>\n          \t<h4>Shave hours off your workday with VBA and macros<\/h4>\n            <p>Automate repetitive tasks, format spreadsheets quickly, and more\n\n<\/p>\n\t\t\t  <\/li>\n      <\/ul>\n        \n      <a class=\"cta-link orange-button-medium\" href=\"https:\/\/breakingintowallstreet.com\/excel-vba\/\" target=\"_blank\">Full Details<\/a>\n      \n      <a class=\"cta-link orange-button-medium bg-blue\" href=\"https:\/\/biws-support.s3.us-east-1.amazonaws.com\/Course-Outlines\/Excel-VBA-Course-Outline.pdf\" target=\"_blank\" rel=\"noopener\">Short Outline<\/a>\n    <\/div>\n<\/div>\n<\/div>\n\n<style>.enteremail__large--inline{margin:60px auto!important}<\/style>\n<h2><span class=\"ez-toc-section\" id=\"How_Database_Functions_Work\"><\/span>How Database Functions Work<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A few notes on the functionality in the screenshot above:<\/p>\n<p>1) The <strong>order<\/strong> of the fields in this area <u>must<\/u> be the same as the order of the fields in the table itself (Order_Table). If Order Date follows Amount in the table, Order Date must follow Amount here:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-22243 size-large\" title=\"Excel Database Functions - Order of the Fields\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-02-1-1024x395.jpg\" alt=\"Excel Database Functions - Order of the Fields\" width=\"1024\" height=\"395\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-02-1-1024x395.jpg 1024w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-02-1-300x116.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-02-1-768x296.jpg 768w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-02-1-1536x592.jpg 1536w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-02-1.jpg 1752w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>2) You do <strong>NOT<\/strong> need to use <em>all<\/em> the fields in the table \u2013 you can choose any of them. We only use a few fields from the table here.<\/p>\n<p>3) And you can <strong>repeat<\/strong> the same field multiple times as long as the repeats are all entered after the first entry, with nothing in between.<\/p>\n<p>4) In a single row, the conditions are joined with <strong>AND<\/strong>. In other words, for the first row here, matching entries must be in the \u201cIndustrials\u201d industry, the \u201cMidwest\u201d region, AND between January 1, 2021 and December 31, 2024.<\/p>\n<p>5) Multiple rows are joined with <strong>OR<\/strong>. So, in the example above, matching entries must be in the \u201cIndustrials\u201d industry, the \u201cMidwest\u201d region, AND between January 1, 2021 and December 31, 2024\u2026 <strong>OR<\/strong> they must be in the \u201cEnergy\u201d industry, the \u201cNortheast\u201d region, AND between January 1, 2021 and December 31, 2024.<\/p>\n<p>6) The last part \u2013 Summary!$J$6:$P$8 \u2013 cannot include empty rows, or Database functions such as DSUM will sum up the entire table.<\/p>\n<p>Database functions are most useful for writing queries with complex criteria, such as ones that involve multiple dates, amounts, regions, industries, and more.<\/p>\n<p>They tend to be overkill for simple queries, such as summing up all orders between two dates, or summing up all orders in a certain industry; for those, SUMIFS and SUMPRODUCT are fine.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"The_Most_Common_Functions\"><\/span>The Most Common Functions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The most common Database function is DSUM, which looks at all the rows in a table and sums up a specific field (column) in each matching row:<\/p>\n<p>=DSUM(Database, Field, Criteria)<\/p>\n<p>The <strong>Database<\/strong> part is the <strong>range of cell references<\/strong>, which must contain the field names in the header. This range should ideally be a Data Table, but it can be any range of cells in the spreadsheet.<\/p>\n<p>The <strong>Field<\/strong> part is the <strong>column or field you want to add up or count<\/strong>. You can use a column number or the exact name in text; it\u2019s best to create a direct link to the title in the table header to avoid errors.<\/p>\n<p>The <strong>Criteria<\/strong> part is the smaller range we created above: Summary!$J$6:$P$8.<\/p>\n<p>It must include at least one field name that\u2019s in the Database AND at least one other condition to be evaluated. If it does not, DSUM will sum up everything in the table.<\/p>\n<p>Each function mentioned above &#8211; DSUM, DCOUNT, DCOUNTA, and DGET &#8211; accepts these same inputs: Database, Field, and Criteria.<\/p>\n<p>All the normal operators, such as &lt;, &gt;, &lt;=, &gt;=, &lt;&gt;, =, *, and ?, still work in the Criteria range of cells, but only if they make logical sense for the underlying data.<\/p>\n<p><strong>The biggest problem with Database functions is that it\u2019s extremely easy to make a small mistake that results in the entire function not working.<\/strong><\/p>\n<p>For example:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-22244 size-full\" title=\"Incorrect Database Function\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-03-1.jpg\" alt=\"Incorrect Database Function\" width=\"934\" height=\"325\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-03-1.jpg 934w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-03-1-300x104.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075453\/Excel-Database-Functions-03-1-768x267.jpg 768w\" sizes=\"(max-width: 934px) 100vw, 934px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Why did these functions suddenly stop working? Because we hard-coded the \u201cRegion\u201d field in the header and added an extra space at the end:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-22245 size-full\" title=\"Incorrect Database Function - Problem Highlighted\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-04-1.jpg\" alt=\"Incorrect Database Function - Problem Highlighted\" width=\"905\" height=\"321\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-04-1.jpg 905w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-04-1-300x106.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-04-1-768x272.jpg 768w\" sizes=\"(max-width: 905px) 100vw, 905px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>This problem shows you why it\u2019s best to link directly to the field names in the Order Table here.<\/p>\n<p>Besides this issue, another drawback of database functions is that it\u2019s not easy to see <strong>trends and patterns<\/strong> when you use them.<\/p>\n<p>For example, how have sales to Energy companies changed over 5-10 years? What percentage of total sales did they represent each year, and which sales reps were most responsible?<\/p>\n<p>For those types of tasks, you are better off using pivot tables and related functionality, such as Power Pivot, which we cover in our <a href=\"https:\/\/breakingintowallstreet.com\/excel-financial-modeling-fundamentals\/\" target=\"_blank\" rel=\"noopener noreferrer\">Excel &amp; Fundamentals course<\/a>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Excel_Database_Functions_Multiple_Criteria\"><\/span><strong>Excel Database Functions Multiple Criteria<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you want to set up a function with multiple criteria, remember the rules above: individual fields in a row are joined together with an AND, and individual rows are joined together with an OR.<\/p>\n<p>Therefore, the following function:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-22246 size-large\" title=\"Excel Database Functions Multiple Criteria\" src=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-05-1-1024x291.jpg\" alt=\"Excel Database Functions Multiple Criteria\" width=\"1024\" height=\"291\" srcset=\"https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-05-1-1024x291.jpg 1024w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-05-1-300x85.jpg 300w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-05-1-768x218.jpg 768w, https:\/\/biwsuploads-assest.s3.amazonaws.com\/biws\/wp-content\/uploads\/2020\/03\/19075452\/Excel-Database-Functions-05-1.jpg 1134w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Will do the following:<\/p>\n<p>1) First, it will find and add all Order Amounts in the Industrials industry AND in the Midwest AND placed between January 1, 2021 and December 31, 2024 (inclusive).<\/p>\n<p>2) Then, it will find and add all Order Amounts in the Industrials industry AND in the Northeast AND placed between January 1, 2021 and December 31, 2024 (inclusive).<\/p>\n<p>3) Next, it will find and add all Order Amounts in the Energy industry AND in the Midwest AND placed between January 1, 2021 and December 31, 2024 (inclusive).<\/p>\n<p>4) Finally, it will find and add all Order Amounts in the Energy industry AND in the Northeast AND placed between January 1, 2021 and December 31, 2024 (inclusive).<\/p>\n<p>Since each row is joined with an OR, the function will then add up <span style=\"text-decoration: underline;\">all<\/span> these Order Amounts.<\/p>\n<p>When you enter multiple rows of criteria, you always get results that match <em>any<\/em> of the rows.<\/p>\n<p>Database functions have their uses, but we tend to use them less than <a href=\"https:\/\/breakingintowallstreet.com\/kb\/excel\/sensitivity-analysis-excel\/\" target=\"_blank\" rel=\"noopener noreferrer\">sensitivity analysis<\/a> in financial models and less than pivot tables in data analysis.<\/p>\n<p>Want to apply these skills? <a href=\"https:\/\/mergersandinquisitions.com\/3-statement-model\/\" target=\"_blank\" rel=\"noopener\">Learn more about 3 statement models<\/a> here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this lesson, you\u2019ll learn how to query and aggregate data tables more effectively with Database Functions such as DSUM and DCOUNT \u2013 and you\u2019ll understand how to enter complex sets of AND and OR conditions to do so.<\/p>\n","protected":false},"featured_media":29301,"template":"","class_list":["post-22072","biws_kb","type-biws_kb","status-publish","has-post-thumbnail","hentry","kb_category-excel"],"acf":[],"_links":{"self":[{"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/biws_kb\/22072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/biws_kb"}],"about":[{"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/types\/biws_kb"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/media\/29301"}],"wp:attachment":[{"href":"https:\/\/breakingintowallstreet.com\/wp-json\/wp\/v2\/media?parent=22072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}