Forum Discussion
Cumulative Recurring SUM per Sector
Hi all,
Looking for some help to calculate a cumulative recurring total per sector.
Basically, i have the following data (with around 50 different IDs, and 12 differents sectors).
ID | Sector | Savings per year | Start Date | End date |
1 | HR | 32,353.13 $ | 2018-10-15 | 2019-10-15 |
2 | IT | 32,353.13 $ | 2018-12-15 | 2019-02-15 |
3 | HR | 662,291.67 $ | 2018-12-15 | 2019-03-15 |
4 | OP | 32,353.13 $ | 2018-12-15 | 2019-10-15 |
5 | IT | 841,500.00 $ | 2018-09-15 | 2019-10-15 |
I want to calculate the monthly saving (therefore, divings the savings per year by 12) and showing the monthly cumulative savings by sector.
For example:
- For Jan 2019, I want to have a total of all savings / 12 (As january 2019 is between the start date and end date). It would be broken down the following way: (HR (662K + 32K) + IT (32K + 841K)+OP(32K))/12 = Total saved for january 2019.
However, when I tried calculating it a new measure, I get the following chart:
This is the formula I have used to calculate the cumulative gain:
Total savings per month = CALCULATE( SUM(TableOperationnel[Savings per year]), FILTER( ALLSELECTED(TableOperationnel), TableOperationnel[Start Date] <= MAX(TableOperationnel[Start Date]) ) )
Has anyone faced a similar situation before? Any help would be appreciated!
Thanks :)
Ben
Hi,
Do you want something like this. You may download my file from here. I am accumulating savings from the start of the Year (January 1), rather than the start of the period for which data is available.
When I tried to use Dates from the 'Dates' table, it generates an error.
What was the error? Was it related to the bi-drectional relationship between the Dates and the Operational table? I'm not sure why you'd do that. Normally I'd have a 1 to many relationship from Dates to a fact/transaction table.
Any idea how to make it the reccuring saving appear for every month that is between [Start Date] and [End Date]?
You can't do a between join using relationships in a tabular model. But you can achieve the same effect by not having a join between your Date and Operational tables and doing the "between join" logic in a measure.
I used the following 2 measures to achieve the output above.
Amt = sumx( filter(sales, Sales[StartDate] < Max('Date'[Date]) && Sales[EndDate] > min('Date'[Date]) ) , Sales[Amount])Cummulative Amt = CALCULATE( [Amt] , FILTER(ALL('date'), 'Date'[Date] <= max('Date'[Date])) )You can download a copy of this model from here
16 Replies
- d_gosbellSuper User
I think this issue is because you are using ALLSELECTED, so for the October column in your chart ALLSELECTED will only return October dates (as October is part of the current selection).
If you switch this to use the ALL(TableOperationnel[Start Date]) function it should fix your issue.
eg.
Total savings per month =
CALCULATE(
SUM(TableOperationnel[Savings per year]),
FILTER(
ALL(TableOperationnel[Start Date]),
TableOperationnel[Start Date] <= MAX(TableOperationnel[Start Date])
)
)
- AnonymousNot applicable
Hi d_gosbell,
Thanks a lot for your reponse! Your suggestion worked as it seems to show now in Power BI all the data I had in my data source (See screnshot below):
However, the reccuring saving appears only once instead of appearing for every month. For example, the saving that appears in novembre (which therefore, has a start date somewhere in novembre), does not appear for the subsequent month. It should also be divided by 12 to illustrated the average monthly saving.How could I go from the current chart to one that:
- Divides the saving by 12
- Appears at every month between start date and end
- is grouped by sector
Do I have to create a new table? Is there a specific function/formula that can process this logic?
Thanks!
Ben- d_gosbellSuper User
So normally I split all of my descriptive columns that I want to do grouping and filtering on into separate tables. So I'd have a table for dates that might have Date, Month, Quarter, Year, etc and a table for the sectors. I think the problem here is that each month is only doing the cumulative sum for sectors that have values in that month. Having the sectors in a separate table that is related to your main data table would avoid this issue.
However we can possibly also fix this by using ALL() over the sector column and if you want to divide this by 12 you should be able to add this at the end.
eg.
Total savings per month =
CALCULATE(
SUM(TableOperationnel[Savings per year]),
FILTER(
ALL(TableOperationnel[Start Date]),
TableOperationnel[Start Date] <= MAX(TableOperationnel[Start Date])
),
ALL(TableOperationnel[Sector])
) / 12
- Ashish_MathurSuper User
Hi,
I do not understand. ID 3 is for a duration for 3 months only. Why should the number be divided by 12? Savings per month shoul d be number/3. Am i correct?
- AnonymousNot applicable
Thank you very much to both of you for your help!
Ashish_Mathur's solution ended working for me. d_gosbell The difference between both of your solutions was that Ashish's was cumulative per month. My graph now looks like Ashish's graph in his previous response.
Thanks again to both of you :)
Ben- Ashish_MathurSuper User
You are welcome.
- d_gosbellSuper User
Ashish_Mathur's solution ended working for me. d_gosbell The difference between both of your solutions was that Ashish's was cumulative per month. My graph now looks like Ashish's graph in his previous response.I think the main difference in our approaches is that I've done a "Lifetime to Date" while Ashish has done a "Year to Date" (so it resets on the first month of the year). Both are valid depending on the requirements
- AnonymousNot applicable
Hi,
Just reviewed both of your solutions more in details. Both actually hepled as I also used d_gosbell to not keep a YTD limit.
I have also ended up using his formulas as the SUMX seemed to represent more the actual recurring savings per month.
Ashish's solution helped me set one line per month in between start date and end date.
Thanks and cheers,
Ben