Forum Discussion
Splitting Values between months of two dates
- 9 years ago
To achieve it, you need to create a calendar table and crossjoin your original table and this calendar table.
In your original table, create a column use the DAX below.
CostPerMonth = Table1[Cost]/(DATEDIFF(Table1[StartdDate],Table1[EndDate],MONTH)+1)Create a calendar table
Calendar = FILTER(CALENDAR("2016-01-01","2017-12-31"),DAY([Date])=1)Crossjoin those two tables.
Table = FILTER(CROSSJOIN(Table1,'Calendar'),'Calendar'[Date]>=Table1[StartdDate]&&'Calendar'[Date]<=Table1[EndDate].[Date])And then you can show your expected result by using a martix visual.
Regards,
Charlie Liao
I don't understand what "Project Cost" is an how it should be calculated.
Sorry for the confusion, i have corrected the column name. The 4th Column in the first table contains Project Cost between for the period of the 2 Dates. Considering second Row for example:
| Id | Benefit Start Date | Benefit End Date | Project Cost |
| 2760 | 9/1/2016 | 3/31/2017 | $5,038.00 |
In this case the Project Value is divided by number of months between those 2 dates to get PerMonthCost (5038 / 7 = 720). Then has to be show on a table month on month. Likewise for all the project Cost is split and to show perMonth Total cost for a given month.
| Running Months | Sum of Per Month Saving |
| Sep | 720 |
| Oct | 720 |
| Nov | 720 |
| Dec | 720 |
| Jan | 720 |
| Feb | 720 |
| Mar | 720 |
| Total | 5038 |
So ideally for a given month what would be its total cost. Hope, i was able to explain better. This is want i am trying to acomplish using DAX for Power BI report. here is the excel file for this sample data.
https://1drv.ms/u/s!Asht7QhPGrBBhyuQpjzcCkc9HUtQ
In this excel sheet only Data sheet goes to PowerBI. Transform Tab is for reference.
- v-caliao-msft9 years ago
Microsoft Employee
To achieve it, you need to create a calendar table and crossjoin your original table and this calendar table.
In your original table, create a column use the DAX below.
CostPerMonth = Table1[Cost]/(DATEDIFF(Table1[StartdDate],Table1[EndDate],MONTH)+1)Create a calendar table
Calendar = FILTER(CALENDAR("2016-01-01","2017-12-31"),DAY([Date])=1)Crossjoin those two tables.
Table = FILTER(CROSSJOIN(Table1,'Calendar'),'Calendar'[Date]>=Table1[StartdDate]&&'Calendar'[Date]<=Table1[EndDate].[Date])And then you can show your expected result by using a martix visual.
Regards,
Charlie Liao
- FreedJustine7 years ago
Helper I
Hi, the formula was very useful, but what if you have an overlapping date range.
e.g start date is Jan 15, 2019
end date is feb 10, 2019
how would you group them by month. Thanks!
- Sabarikumar75799 years ago
Helper I
Awsome, Charlie !!!! I got the required output. Thank You
- Anonymous8 years agoNot applicable
I have a similar issue and used the solution to create a table as mentioned.
in my case the total of original value and the crossjoin table is not adding up. Formula usedThe final output:
Can you please help me with this