Measuring inflation depends on what level of the price chain the investor or market student is considering. Each inflation indicator serves a specific purpose of measuring price changes within a determined segment, be it a level in the supply chain (commodity prices, import prices, producer prices, wholesale prices) or at the consumption level ( consumer price index, or personal consumption expenditures price index).
Most inflation indicators contain several elements at different weightings depending on their representation and use in the economy.
To track the inflation rate, we calculate the percentage change in the index number on a year-on-year basis, which means its percentage change from the same month of the past year.
The month-on-month percentage change can also be used to track short-term price fluctuations. However, the percentage change from a year ago, which tracks long-term inflation, is the way investors, economists, and policymakers use the most.

Measuring inflation with the GDP deflator:

Real GDP counts for the total production of goods and services valued at base year prices. The deflator measures the evolution prices between the two years. When the value of production increases over the course of a year, it is therefore important to know if this is due to an increase in quantity or volume of real production or rather an increase in prices.
To do this, we divide the measures of production in value (output at market price) by an index price variation. This operation transforms measurements in current prices (which include price increases) into constant prices (which exclude them).

the table below gives an example of how the GDP Deflator is calculated:

 20192020formula
production value at market prices$1250$1500Given data
price index (base year 2015=100)114116Given data
production value at constant prices$1096,5$1293,1= (1500/116)*100
 real GDP growth rate 18%= ((1293,1-1096,5)/1096,5)*100%
GDP deflator annual rate 2%= ((116-114)/114)*100%
nominal GDP growth rate 20%= ((1500-1250)/1250)*100%
GDP Deflator Formula

What is the difference between CPI and GDP deflator?

There are two main differences between CPI and GDP deflator:
The deflator concerns the evolution of all the prices of goods and services produced in the territory, while the CPI only includes prices of goods consumed by consumers in this area (territory).
The CPI, therefore, does not include the price of public orders (military equipment, infrastructure, etc.), whereas the deflator does.
Conversely, the CPI incorporates the price of imported goods (imported oil, commodities, finished goods from China and other parts of the world …) while the deflator does not.
The composition of the basket of goods on which the CPI is calculated is only rarely revised. On the other hand, the composition of GDP constantly adjusts to the quantities produced. The deflator is, then, calculated from quantities that are constantly adapting.
Therefore, the inflation rate measured from the CPI and the deflator come together but do not coincide.
Additionally, for non-oil producing countries, oil price shocks affect the CPI more than the deflator because oil is not a national product, so it is not included in the GDP and therefore only affects the GDP deflator indirectly.