Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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
Solved! Go to Solution.
Hi @Anonymous
You can refer to the following example.
The sample data table.
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)
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 @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:
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.
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.
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.
Hi @Anonymous
You can refer to the following example.
The sample data table.
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)
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 @Anonymous
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
hi @Anonymous
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
User | Count |
---|---|
42 | |
28 | |
24 | |
20 | |
16 |
User | Count |
---|---|
54 | |
35 | |
18 | |
18 | |
15 |