cancel
Showing results for
Did you mean:
Regular Visitor

Calculating a value by month in every month of a period

I have a table with a cost column, a start date column and an end date column. I need to create either a measure or a calculated column that gives me the cost for every month/year between the start and end dates to relate with my calendar table and generate graphs with the sum for each month/year.

For example, I have this:

And I need it to be like this, taking the first cost as an example

8 REPLIES 8
Community Support

Hi @aleaa

You can refer to the following example.

Create a new table first:

``````Table 2 = var a=CALENDAR(DATE(2020,1,1),date(2023,12,31))
return GENERATE(SUMMARIZE('Table',[Cost]),a)
``````

Then create a column in new table:

``````Column = var _startdate=LOOKUPVALUE('Table'[Start Date],'Table'[Cost],'Table 2'[Cost])
var _enddate=LOOKUPVALUE('Table'[End Date],'Table'[Cost],'Table 2'[Cost])
return IF([Date]>=_startdate&&[Date]<=_enddate&&DAY([Date])=1,1,0)``````

Then filter the column:

Output:

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Regular Visitor

When I created the column I got an error saying I inputed a table with many values and it was expected to be a single value.

Community Support

Hi @aleaa

Can you provide the picture of error message, and do you create the table, then create the column?

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Regular Visitor

Find the message below (it's in Portuguese). And yes, first I created the table, then the column. I'm not sure why I got an error, but maybe it's because in my table (with the costs) I have similar costs for different periods of time. So I think it didn't find a single correspondent value and didn't know witch one to consider.

Community Champion

hi @aleaa

what do you expect to return on overlapping days like 02/08/2022?

Regular Visitor

nothing, I need it to be just one day for each month/year that has a value

Community Champion

hi @aleaa

For 01/09/2022, why 678 is return, not 235.5?

Regular Visitor

Yes, I need each line to be divided in multiple lines, one for each month with the separate costs. So for 01/09/2022 for example I'd have a line with 678, a line with 235.5, a line with 765.4, a line with 235.6 and a line with 6893

Announcements

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.

Top Solution Authors
Top Kudoed Authors