Get average of a certain component since start of month

I have created a custom sensor (in this case sensor.nordpool_average), which is updated on a daily basis of the daily electric cost. I can access the history of this sensor and see the history, but I would like to get the average (see example).

Is there any way to do this, i.e. create a custom component which takes the history of sensor.nordpool_avreage since start of month up to current day and calculates the average?

Statistics sensor will probably work

That would be great. Any clue on how to configure this?

It’s in the docs.
Statistics - Home Assistant (home-assistant.io)

Just make sure the max age is long enough and that the sampling size is enough to hold all values during the month.

Thank you. However, how do I proceed to config max_age to show me data from start of the month? Last 30 days would be correct only once per month.