Hi community,
I need to calculate last twelve month value of a measure given some conditions. But this calculation should be added as a row with a new dimension member of LTM. Below picture simply illustrates the calculation logic. For Quarter case LTM equals 'latest quarter value' + 'latest year value' - 'previous year quarter value'. In other words 3m + 12m - 3m. For half-year case LTM equals 'latest half-year value' + 'latest year value' - 'previous year half-year value'. In other words 6m + 12m - 6m
But in order to calculate LTM, multiple conditions need to be satisfied. There must be previous period in last year value and last full year value. On top of that, all these values should be in same currency. The challenge is that data is not regular as I do not have always quarter, half-year, year, etc. records. It changes from company to company.
I created below sample input data. My data initially does not include these NULL months. I create those to facilitate rolling if applicable. Let me further clarify case by case:
As you can see the data is quite irregular:
Company | Date | Period | FX | Sales |
CompanyA | 31.12.2016 | Year | USD | 1308 |
CompanyA | 31.01.2017 | |||
CompanyA | 28.02.2017 | |||
CompanyA | 31.03.2017 | |||
CompanyA | 30.04.2017 | |||
CompanyA | 31.05.2017 | |||
CompanyA | 30.06.2017 | H1 | USD | 1767 |
CompanyA | 31.07.2017 | |||
CompanyA | 31.08.2017 | |||
CompanyA | 30.09.2017 | |||
CompanyA | 31.10.2017 | |||
CompanyA | 30.11.2017 | |||
CompanyA | 31.12.2017 | Year | USD | 3680 |
CompanyA | 31.01.2018 | |||
CompanyA | 28.02.2018 | |||
CompanyA | 31.03.2018 | |||
CompanyA | 30.04.2018 | |||
CompanyA | 31.05.2018 | |||
CompanyA | 30.06.2018 | H1 | USD | 1892 |
CompanyA | 31.07.2018 | |||
CompanyA | 31.08.2018 | |||
CompanyA | 30.09.2018 | |||
CompanyA | 31.10.2018 | |||
CompanyA | 30.11.2018 | |||
CompanyA | 31.12.2018 | Year | USD | 4100 |
CompanyA | 31.01.2019 | |||
CompanyA | 28.02.2019 | |||
CompanyA | 31.03.2019 | Q1 | USD | 2823 |
CompanyA | 30.04.2019 | |||
CompanyA | 31.05.2019 | |||
CompanyA | 30.06.2019 | H1 | USD | 8511 |
CompanyA | 31.07.2019 | |||
CompanyA | 31.08.2019 | |||
CompanyA | 30.09.2019 | |||
CompanyA | 31.10.2019 | |||
CompanyA | 30.11.2019 | |||
CompanyA | 31.12.2019 | Year | USD | 6494 |
CompanyA | 31.01.2020 | |||
CompanyA | 29.02.2020 | |||
CompanyA | 31.03.2020 | |||
CompanyA | 30.04.2020 | |||
CompanyA | 31.05.2020 | |||
CompanyA | 30.06.2020 | H1 | USD | 3714 |
CompanyB | 30.06.2017 | Year | EUR | 165 |
CompanyB | 31.07.2017 | |||
CompanyB | 31.08.2017 | |||
CompanyB | 30.09.2017 | |||
CompanyB | 31.10.2017 | |||
CompanyB | 30.11.2017 | |||
CompanyB | 31.12.2017 | |||
CompanyB | 31.01.2018 | |||
CompanyB | 28.02.2018 | |||
CompanyB | 31.03.2018 | |||
CompanyB | 30.04.2018 | |||
CompanyB | 31.05.2018 | |||
CompanyB | 30.06.2018 | Year | EUR | 2242 |
CompanyB | 31.07.2018 | |||
CompanyB | 31.08.2018 | |||
CompanyB | 30.09.2018 | |||
CompanyB | 31.10.2018 | |||
CompanyB | 30.11.2018 | |||
CompanyB | 31.12.2018 | H1 | EUR | 3019 |
CompanyB | 31.01.2019 | |||
CompanyB | 28.02.2019 | |||
CompanyB | 31.03.2019 | |||
CompanyB | 30.04.2019 | |||
CompanyB | 31.05.2019 | |||
CompanyB | 30.06.2019 | Year | EUR | 5940 |
CompanyC | 30.06.2020 | H1 | EUR | 140 |
CompanyC | 31.07.2020 | |||
CompanyC | 31.08.2020 | |||
CompanyC | 30.09.2020 | Q3 | EUR | 85 |
CompanyD | 30.06.2018 | H1 | USD | 798 |
CompanyD | 31.07.2018 | |||
CompanyD | 31.08.2018 | |||
CompanyD | 30.09.2018 | |||
CompanyD | 31.10.2018 | |||
CompanyD | 30.11.2018 | |||
CompanyD | 31.12.2018 | Year | USD | 2056 |
CompanyD | 31.01.2019 | |||
CompanyD | 28.02.2019 | |||
CompanyD | 31.03.2019 | |||
CompanyD | 30.04.2019 | |||
CompanyD | 31.05.2019 | |||
CompanyD | 30.06.2019 | H1 | USD | 2200 |
CompanyD | 31.07.2019 | |||
CompanyD | 31.08.2019 | |||
CompanyD | 30.09.2019 | |||
CompanyD | 31.10.2019 | |||
CompanyD | 30.11.2019 | |||
CompanyD | 31.12.2019 | Year | EUR | 4778 |
CompanyD | 31.01.2020 | |||
CompanyD | 29.02.2020 | |||
CompanyD | 31.03.2020 | |||
CompanyD | 30.04.2020 | |||
CompanyD | 31.05.2020 | |||
CompanyD | 30.06.2020 | H1 | USD | 2494 |
CompanyE | 31.12.2016 | Year | EUR | 4591 |
CompanyE | 31.01.2017 | |||
CompanyE | 28.02.2017 | |||
CompanyE | 31.03.2017 | Q1 | EUR | 1214 |
CompanyE | 30.04.2017 | |||
CompanyE | 31.05.2017 | |||
CompanyE | 30.06.2017 | H1 | EUR | 2493 |
CompanyE | 31.07.2017 | |||
CompanyE | 31.08.2017 | |||
CompanyE | 30.09.2017 | Q3 | EUR | 1333 |
CompanyE | 31.10.2017 | |||
CompanyE | 30.11.2017 | |||
CompanyE | 31.12.2017 | Year | EUR | 5177 |
CompanyE | 31.01.2018 | |||
CompanyE | 28.02.2018 | |||
CompanyE | 31.03.2018 | Q1 | EUR | 1406 |
CompanyE | 30.04.2018 | |||
CompanyE | 31.05.2018 | |||
CompanyE | 30.06.2018 | H1 | EUR | 2855 |
CompanyE | 31.07.2018 | |||
CompanyE | 31.08.2018 | |||
CompanyE | 30.09.2018 | Q3 | EUR | 1546 |
CompanyE | 31.10.2018 | |||
CompanyE | 30.11.2018 | |||
CompanyE | 31.12.2018 | Year | EUR | 6357 |
CompanyE | 31.01.2019 | |||
CompanyE | 28.02.2019 | |||
CompanyE | 31.03.2019 | |||
CompanyE | 30.04.2019 | |||
CompanyE | 31.05.2019 | |||
CompanyE | 30.06.2019 | |||
CompanyE | 31.07.2019 | |||
CompanyE | 31.08.2019 | |||
CompanyE | 30.09.2019 | YTD | EUR | 5419 |
CompanyE | 31.10.2019 | |||
CompanyE | 30.11.2019 | |||
CompanyE | 31.12.2019 | Year | EUR | 7419 |
CompanyF | 31.12.2018 | Year | GBP | 5299 |
CompanyF | 31.01.2019 | |||
CompanyF | 28.02.2019 | |||
CompanyF | 31.03.2019 | Q1 | GBP | 1398 |
CompanyF | 30.04.2019 | |||
CompanyF | 31.05.2019 | |||
CompanyF | 30.06.2019 | H1 | GBP | 2638 |
CompanyF | 31.07.2019 | |||
CompanyF | 31.08.2019 | |||
CompanyF | 30.09.2019 | YTD | GBP | 3849 |
CompanyF | 31.10.2019 | |||
CompanyF | 30.11.2019 | |||
CompanyF | 31.12.2019 | Year | GBP | 5332 |
CompanyF | 31.01.2020 | |||
CompanyF | 29.02.2020 | |||
CompanyF | 31.03.2020 | Q1 | GBP | 1970 |
CompanyF | 30.04.2020 | |||
CompanyF | 31.05.2020 | |||
CompanyF | 30.06.2020 | H1 | GBP | 4397 |
CompanyF | 31.07.2020 | |||
CompanyF | 31.08.2020 | |||
CompanyF | 30.09.2020 | YTD | GBP | 5661 |
Desired output to be added back to original data:
Company | Date | Period | FX | Sales |
CompanyA | 30.06.2018 | LTM | USD | 3805 |
CompanyA | 30.06.2019 | LTM | USD | 1697 |
CompanyD | 30.06.2019 | LTM | USD | 3458 |
CompanyE | 31.03.2018 | LTM | EUR | 5369 |
CompanyE | 30.06.2018 | LTM | EUR | 5539 |
CompanyE | 30.09.2018 | LTM | EUR | 5752 |
CompanyE | 30.09.2019 | LTM | EUR | 7375 |
CompanyF | 31.03.2020 | LTM | GBP | 5904 |
CompanyF | 30.06.2020 | LTM | GBP | 7091 |
CompanyF | 30.09.2020 | LTM | GBP | 7144 |
I think it requires Batch Macro kind of approach. I am quite new and not much sophisticated to be honest. Any guidance would be deeply appreciated.
Thanks a lot
Hi @onanm it seems like the community was busy yesterday and your post slipped through the net, I imagine this may be down to the complexity of the problem and the time it may take someone to jump in and help.
I think we can potentially make your problem a bit clearer which may encourage more people to take a look. Specifically, it may be helpful to add, into your desired output table, three new columns, one containing the calculation used in it's raw form (Q1+H1....), one containing the values that translates to (1+4-3...) and a third one, which indicates the row numbers from which that information was gathered.
This may make your problem just a bit easier to understand.
I don't think this is a batch macro problem though, so I wouldn't go looking down that hole (I mean you can and it may provide you with a solution, but it would be an unnecessary detour).
Ben
User | Count |
---|---|
18 | |
14 | |
13 | |
9 | |
8 |