Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Aggregate at change in value

$
0
0

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.

 

DocumentNumberEmployeeRegionEstablishmentTransaction DateTransaction Amount
10395345125123456EASTMarriott2/15/2015$359
23450971252123456WESTHyatt3/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:

 

DocumentNumberEmployeeExpense TypeReceipt DateExpense Amount
10395345125123456Hotel2/15/2015$150
10395345125123456Meal2/15/2015$30
10395345125123456Hotel2/16/2015$150
10395345125123456Meal2/16/2015$29
23450971252123456Hotel3/15/2015$190
23450971252123456Meal3/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 NbrEmployeeRegionEstabExp TypeTranx DateReceipt DateTrnx AmtExp Amt
10395345125123456EASTMarriottHotel2/15/20152/15/2015$359 $150
10395345125123456EASTMarriottMeal2/15/20152/15/2015$359 $30
10395345125123456EASTMarriottHotel2/15/20152/16/2015$359 $150
10395345125123456EASTMarriottMeal2/15/20152/16/2015$359 $29
23450971252123456WESTHyattHotel3/15/20153/15/2015$233 $190
23450971252123456WESTHyattMeal3/15/20153/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 LabelsSum of Trnx AmtSum of Exp Amt
Marriott1436359
Hyatt466233
Grand Total1902592

 

But I want to see this, since there is only a TOTAL of 592 in transaction amounts:

Row LabelsSum of Trnx AmtSum of Exp Amt
Marriott359359
Hyatt233233
Grand Total592592

 

 

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.


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>