Forum Discussion
LTM calculation using different reference dates
Hi All,
We have a scenario wherein a corporation has on-boarded other businesses and all the details are available in Subsidiary master table. Sample data below...
Org Id | Name | Integration Month |
1 | Business 1 | Feb-21 |
2 | Business 2 | Dec-19 |
3 | Business 3 | Oct-18 |
We have Sales transaction tables historic and current (with same structure)
Org Id | Month | Value (Historic) |
1 | Jan-20 | 100 |
1 | Feb-20 | 200 |
1 | Mar-20 | 120 |
2 | Sep-19 | 100 |
2 | Aug-19 | 300 |
2 | Nov-19 | 120 |
3 | Jul-18 | 100 |
3 | Apr-18 | 100 |
3 | Sep-18 | 120 |
Org Id | Month | Value (Current) |
1 | Jan-22 | 100 |
1 | Feb-22 | 200 |
1 | Mar-22 | 120 |
2 | Jan-22 | 100 |
2 | Feb-22 | 300 |
2 | Mar-22 | 120 |
3 | Jan-22 | 100 |
3 | Feb-22 | 100 |
3 | Mar-22 | 120 |
Requirement is to calculate the last 12 months Sales Value (Historic) data (for each business) based on the "integration month" in the master.
expected sample output..
Org Id | LTM Value Historic |
1 | 420 (100 + 200 + 120) |
2 | 520 (100 + 300 + 120) |
3 | 320 (100 + 100 + 120) |
the sample data has been provided only for 3 months.
Thanks.
- Anonymous3 years ago
Hi powerbiAG ,
If you want to calculate the last 12 months Sales Value (Historic) data (for each business) based on the "integration month" in the fact table, I think LTM Value Historic for Org Id =1 should be 200+120 instead of 100+200+120. Due to Integration Month for Org Id =1 is 2021/Feb, so last 12 month should be from 2020/Feb to 2021/Jan. So 2020/Jan is not in range.
Try code as below to create a calculated column.
LTM Value Historic = VAR _Last12months = FILTER ( CALENDARAUTO (), [Date] <= EOMONTH ( 'Table'[Integration Month], -1 ) + 1 && [Date] >= EOMONTH ( 'Table'[Integration Month], -13 ) + 1 ) RETURN CALCULATE ( SUM ( 'Sales transaction (historic)'[Value (Historic)] ), FILTER ( 'Sales transaction (historic)', 'Sales transaction (historic)'[Month] IN _Last12months ) )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- AnonymousNot applicable
Hi powerbiAG ,
If you want to calculate the last 12 months Sales Value (Historic) data (for each business) based on the "integration month" in the fact table, I think LTM Value Historic for Org Id =1 should be 200+120 instead of 100+200+120. Due to Integration Month for Org Id =1 is 2021/Feb, so last 12 month should be from 2020/Feb to 2021/Jan. So 2020/Jan is not in range.
Try code as below to create a calculated column.
LTM Value Historic = VAR _Last12months = FILTER ( CALENDARAUTO (), [Date] <= EOMONTH ( 'Table'[Integration Month], -1 ) + 1 && [Date] >= EOMONTH ( 'Table'[Integration Month], -13 ) + 1 ) RETURN CALCULATE ( SUM ( 'Sales transaction (historic)'[Value (Historic)] ), FILTER ( 'Sales transaction (historic)', 'Sales transaction (historic)'[Month] IN _Last12months ) )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- powerbiAGFrequent Visitor
Hi Rico,
Thanks for the reply.
I tried to replicate your solution, but am getting error which says "A single value for column 'Integration Month' in table 'Table' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum...."
Am I missing something ?
Any advise would be highly appreciated.
- powerbiAGFrequent Visitor
Anonymous any thoughts on the above please...