Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

You can refer to the following example.

The sample data table.

vxinruzhumsft_2-1675067929208.png

Modified the column in table 2

 

Column = IF(COUNTROWS(FILTER('Table',[Cost]=EARLIER('Table 2'[Cost])&&EARLIER('Table 2'[Date])>='Table'[Start Date]&&EARLIER('Table 2'[Date])<='Table'[End Date]))>0&&DAY([Date])=1,1,0)

 

vxinruzhumsft_3-1675067951140.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.

 

View solution in original post

9 REPLIES 9
v-xinruzhu-msft
Community Support
Community Support

Hi @Anonymous 

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.

Anonymous
Not applicable

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 @Anonymous 

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.

 

Anonymous
Not applicable

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

 

Hi @Anonymous 

You can refer to the following example.

The sample data table.

vxinruzhumsft_2-1675067929208.png

Modified the column in table 2

 

Column = IF(COUNTROWS(FILTER('Table',[Cost]=EARLIER('Table 2'[Cost])&&EARLIER('Table 2'[Date])>='Table'[Start Date]&&EARLIER('Table 2'[Date])<='Table'[End Date]))>0&&DAY([Date])=1,1,0)

 

vxinruzhumsft_3-1675067951140.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.

 

FreemanZ
Super User
Super User

hi @Anonymous 

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

Anonymous
Not applicable

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

hi @Anonymous 

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

Anonymous
Not applicable

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors