# How to Calculate Cost of Goods Sold in PostgreSQL

Learn how to calculate Cost of Goods Sold (COGS) with your inventory and purchases. Discover industry averages and related platforms like Stripe and Shopify.

Optimizing the Cost Of Goods (COGS) sold is one of the best ways to determine the total cost of your production that will be useful in calculating your gross profit. By definition, the Cost of Goods Sold is the direct cost of producing the goods sold by a company (thanks, Investopedia!). While the metric seems simple on the surface, it gives valuable insights into areas of future growth and improvement. We'll take you through how to calculate this metric, how to understand it in the context of your industry, and how to apply it to the platforms you're using now.

## How to Calculate the Cost of Goods Sold

You can calculate COGS by adding the beginning inventory and purchases made during the period, then subtracting the ending inventory from it. COGS can be assessed for various time-periods (i.e. day, week, month, year) and, if your purchases, beginning inventory, and ending inventory are tied to certain products or campaigns, you can assign a specific COGS for each.

If you’re confused about how to define the beginning inventory, purchases, and ending inventory, we’ve included some nifty definitions and examples below:

• Beginning inventory is the leftover inventory from the last year or month that was not sold. This includes the products or merchandise that were not sold in the previous month or year.
• Purchase during the period is the additional purchases or productions that the manufacturers or company has made. This includes the raw materials and cost of labor for the additional products made.
• Ending inventory is the number of products that are not sold at the end of the month or year. This will be used as the beginning inventory for your next month/year’s COGS calculation.

You may be wondering, how do I know which value to attribute to each unit of inventory if I bought materials at different prices? There are three methods to answer this question: Weighted Average Cost (WAC); First in, First out (FIFO); and Last in, First out (LIFO). Each presents a general rule to make calculating COGS consistent over time and across businesses. We recommend reading about each method’s pros and cons and deciding which works best for your business.

When choosing how to calculate COGS, remember: consistency is key! That means, if you decide to use LIFO for the month, you should do that for the next month’s COGS as well. Having consistent metrics will allow you to better identify the causes of good or bad performance.

## How to Calculate Metric in PostgreSQL

It can be difficult to calculate this metric in PostgreSQL, but we have a quick and easy solution, Lido.app. Read below to learn more and get started today.

## What is Lido?

Lido allows you to connect, analyze, and visualize all of your data in a single spreadsheet. Don't wait for engineers to build analysis dashboards! Lido provides a simple and easy solution to importing data from numerous platforms. Automatically import data from your favorite platforms such as Shopify, Facebook, Google Analytics, and many more and apply Lido's software to extract meaningful metrics from them. After applying Lido software to your data, you will be left with sleek, attractive dashboards to share with your stakeholders, rather than confusing and jumbled raw data. Furthermore, the dashboards are easily editable to focus on specific data or metrics.