I have a table with power plant capacities in different years. There are only entries when something changes in the capacities. In the years not listed, the last value applies.
Plant | Year | Capacity |
---|---|---|
Cottam | 2003 | 800 |
Cottam | 2009 | 600 |
Cottam | 2015 | 800 |
Drax | 2000 | 600 |
Drax | 2005 | 1200 |
Drax | 2010 | 1800 |
Drax | 2013 | 1200 |
Drax | 2020 | 0 |
Ironbridge | 2007 | 500 |
Ironbridge | 2015 | 0 |
Now I would like to transform the initial table, so that I also have values for all years in between and can display them in a stacked column chart, for example. The result should look like shown in the table below. Marked in yellow are the numbers from the initial table.
Here's how to solve this (more easily) in DAX:
Calendar =
SELECTCOLUMNS(
GENERATESERIES(
MIN(Plants[Year]),
MAX(Plants[Year])
),
"Year", [Value]
)
Last Given Capacity =
VAR current_year =
MAX(Calendar[Year])
VAR last_capacity_year =
CALCULATE(
MAX(Plants[Year]),
'Calendar'[Year] <= current_year
)
RETURN
CALCULATE(
MAX(Plants[Capacity]),
Calendar[Year] = last_capacity_year
)
X-axis: 'Calendar'[Year]
Y-axis: [Last Given Capacity]
Legend: 'Plants'[Plant]