I'm trying to find a way to aggregate data only at changes in a specific dimension when joining tables of different granularity in HANA.
Let's say I have 1 table that stores corporate card transactions, and I have 2 transactions for hotel stays.
| DocumentNumber | Employee | Region | Establishment | Transaction Date | Transaction Amount |
| 10395345125 | 123456 | EAST | Marriott | 2/15/2015 | $359 |
| 23450971252 | 123456 | WEST | Hyatt | 3/15/2015 | $233 |
I also have an internal expense system to break these down into smaller parts. The first transaction was for a 2 night stay including meals. The second for a 1 night stay including meals:
| DocumentNumber | Employee | Expense Type | Receipt Date | Expense Amount |
| 10395345125 | 123456 | Hotel | 2/15/2015 | $150 |
| 10395345125 | 123456 | Meal | 2/15/2015 | $30 |
| 10395345125 | 123456 | Hotel | 2/16/2015 | $150 |
| 10395345125 | 123456 | Meal | 2/16/2015 | $29 |
| 23450971252 | 123456 | Hotel | 3/15/2015 | $190 |
| 23450971252 | 123456 | Meal | 3/15/2015 | $43 |
I want to be able to combine these into a single view for a report. If I join these together on the Document Number field, I get this, where the transaction amount is repeated on multiple expense lines:
| Doc Nbr | Employee | Region | Estab | Exp Type | Tranx Date | Receipt Date | Trnx Amt | Exp Amt |
| 10395345125 | 123456 | EAST | Marriott | Hotel | 2/15/2015 | 2/15/2015 | $359 | $150 |
| 10395345125 | 123456 | EAST | Marriott | Meal | 2/15/2015 | 2/15/2015 | $359 | $30 |
| 10395345125 | 123456 | EAST | Marriott | Hotel | 2/15/2015 | 2/16/2015 | $359 | $150 |
| 10395345125 | 123456 | EAST | Marriott | Meal | 2/15/2015 | 2/16/2015 | $359 | $29 |
| 23450971252 | 123456 | WEST | Hyatt | Hotel | 3/15/2015 | 3/15/2015 | $233 | $190 |
| 23450971252 | 123456 | WEST | Hyatt | Meal | 3/15/2015 | 3/15/2015 | $233 | $43 |
If I want to do ad-hoc analysis on any dimension, how can I ensure the transaction amount only aggregates at changes in the document number?
For example, if I aggregate on Establishment, I will see:
| Row Labels | Sum of Trnx Amt | Sum of Exp Amt |
| Marriott | 1436 | 359 |
| Hyatt | 466 | 233 |
| Grand Total | 1902 | 592 |
But I want to see this, since there is only a TOTAL of 592 in transaction amounts:
| Row Labels | Sum of Trnx Amt | Sum of Exp Amt |
| Marriott | 359 | 359 |
| Hyatt | 233 | 233 |
| Grand Total | 592 | 592 |
Keep in mind this is a simplified example as the expense amounts could be different than the total transaction amount (personal spend). Any help would be appreciated.
Thanks.