@edlng Hi! Here the steps:
1. Create a table with date ranges:
Periods =
DATATABLE(
"Period", STRING,
"Start Date", DATE,
"End Date", DATE,
{
{"May 2021 - July 2022", DATE(2021,5,1), DATE(2022,7,31)},
{"Aug 2022 - Dec 2022", DATE(2022,8,1), DATE(2022,12,31)},
{"Jan 2023 - Jun 2023", DATE(2023,1,1), DATE(2023,6,30)}
-- Add more periods here
}
)
2. Now, you need to create a relationship:
Go to Model View and connect the Periods[Start Date] and Periods[End Date] to your main table's Date column.
3. Calculates these measures:
Total Consumption =
CALCULATE(
SUM('YourTable'[Consumption]),
TREATAS(
FILTER(Periods,
'YourTable'[Date] >= Periods[Start Date] &&
'YourTable'[Date] <= Periods[End Date]
),
'YourTable'[Date]
)
)
Avg Unit Price =
DIVIDE(
SUMX('YourTable', 'YourTable'[Consumption] * 'YourTable'[Average Unit Price]),
SUM('YourTable'[Consumption])
)
Total Cost =
CALCULATE(
SUM('YourTable'[Cost]),
TREATAS(
FILTER(Periods,
'YourTable'[Date] >= Periods[Start Date] &&
'YourTable'[Date] <= Periods[End Date]
),
'YourTable'[Date]
)
)
4. Add a Matrix Visual.
Place:
Rows: Site, Period, Energy Type
Columns: (None, since you want it by row)
Values: Total Consumption, Avg Unit Price, Total Cost
BBF