cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
aleaa
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:

aleaa_0-1674610324175.png

 

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

aleaa_1-1674610376921.png

 

 

8 REPLIES 8
v-xinruzhu-msft
Community Support
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:

vxinruzhumsft_0-1674698913900.png

 

Output:

vxinruzhumsft_1-1674698925199.png

 

vxinruzhumsft_2-1674698952656.png

 

 

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.

Hi @v-xinruzhu-msft 

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.

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.

 

Hi @v-xinruzhu-msft 

 

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.

 

aleaa_0-1674819060703.png

 

FreemanZ
Community Champion
Community Champion

hi @aleaa 

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

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

FreemanZ
Community Champion
Community Champion

hi @aleaa 

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

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

Helpful resources

Announcements
Carousel_PBI_Wave1

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.

Power BI Summit Carousel 2

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!

Thank you 2022 Review

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