Forum Discussion
Cumulative Recurring SUM per Sector
- 7 years ago
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.
- 7 years ago
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
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
Hi to both of you :)
Sorry for the delay, I was trying to solve it myself. Followed Microsoft's training about DAX and did a lot of troubleshooting. Still not able to make it work.
Ashish_Mathur : Eventhoguh ID 3 has a 3 month duration, the savings are an estimate per year. Therefore, the total savings for ID 3 would be (Savings for ID 3/12)*3.
d_gosbell The main issue here is to illustrate the savings for every month per sector. Let me show what I think the logic should be for a specific example (Let's say Jan 2019, for HR sector).
1. Loop through each row (Use SUMX?) in the TableOperationnel.
IF ID's sector is equal to the HR sector
AND
IF [Start Date]< Jan 2019 < [End Date]
2. Divide savings of current ID by 12 AND add it to SUM of savings for JAN 2019 for HR sector
3. Go to the next sector
4. Go to next month
The logic above should be done For each month in the last 12 months (and 12 upcoming months), segmented by sectors.
You'll find the screenshot below of the chart when I tried the calculation you have suggested d_gosbell :
I have also attached the relationship logi
Thanks again for your help folks!
Ben
- d_gosbell7 years agoSuper User
I think the issue with all months pulling the same value is possibly because you have a bi-directional relationship from dates and sectors back to the operational table. The dates should definitely be a one way, one to many relationship to the operations table. I think if you fix up the relationships the graph will fix itself.
And if you are always dividing by 12 the order of the operations should not matter. (1/12) + (3/12) + (5/12) is mathematically the same as (1 + 3 + 5) / 12 (the order is only important if you don't have a common denominator)
- Anonymous7 years agoNot applicable
Thanks d_gosbell!
It definitely works better. I have also changed the 'Tableoperationnel' to 'secteur' to a "one to many" relationship, as one process can only be within one sector/division.Is there a way I can make the savings recurring though? Currently, it seems like the savings are divided by 12, but they do not appear for every month.
Total savings = CALCULATE( SUM(TableOperationnel[annual saving per process]), FILTER( ALL('TableOperationnel'[Start Date]), TableOperationnel[Start Date] <= MAX(TableOperationnel[Start Date]) ), ALL('TableOperationnel'[Secteur]) ) / 12When I tried to use Dates from the 'Dates' table, it generates an error.
Any idea how to make it the reccuring saving appear for every month that is between [Start Date] and [End Date]?
Thanks!
Ben- d_gosbell7 years agoSuper User
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
- Ashish_Mathur7 years agoSuper User
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.
- Anonymous7 years agoNot applicable
Thanks Ashish_Mathur
This chart is exactly what I am looking for. I created similar tables to "Calendar" and a "Month" table, similar to what you did.However, when I looked into your "Data" table, I see that you had 1 date per month per sector. I didn't see any formula for the "Date" column. How did you create 12 lines (For all 12 months in a year) for every sector?
Was it through a formula?
Thanks again Ashish_MathurBen
H
- Ashish_Mathur7 years agoSuper User
You are welcome. Please click on the Query Editor and follow the steps show there. Also, if my reply helped, please mark it as Answer.