How can I calculate % change from a year ago?

I am pulling this dataset - Consumer Price Index for All Urban Consumers: All Items in U.S. City Average (CPIAUCSL) | FRED | St. Louis Fed

How can I calculate % change from a year ago? The dataset has monthly data, so I need to calculate the 12-month difference and the percentage of it.

1 Like

Are you storing this data in a database, and if so, which one?

@grant2 No, I’m pulling it directly to Grafana cloud.

Are you using the Infinity datasource? If not, what is your datasource?

data source is the FRED API, I have provided the link at the top post.

Can you share your query for how your are pulling the monthly data from the FRED API?

You have all the info here - St. Louis Fed Web Services: FRED® API

Please provide a specific rest api endpoint that one can use to test out your data fetch and not some documentation website for us to read to figure out your specific data.

Help us help you

Please use this URL to query FRED data:

Where series_id & api_key need to be inserted by you.

Here is a sample observation

Hi @usrcosmicglow

I put this URL into Infinity datasource to get these results and link the API call with the Grafana time selector (API key obfuscated here):${__from:date:YYYY-MM-DD}&observation_end=${__to:date:YYYY-MM-DD}&api_key=abcdef123456789&file_type=json

with this UQL:

| jsonata "observations"
| project-away "realtime_end", "realtime_start"

to get this:

Next, I wrote a JSONata query to calculate the difference of the current month CPI vs. the CPI from 12 months prior, and displayed the results as the difference and as % change.

| jsonata "observations[0].$number(value)-observations[11].$number(value)"

gives this:

| jsonata "(observations[0].$number(value)-observations[11].$number(value))/observations[0].$number(value)"

gives this:

@grant2 thanks. The issue is that I would like to calculate the running % change from a year ago (meaning the calculation will produce a continuous series of outputs), how do we do that?