Skip to Content
author's profile photo Former Member
Former Member

How to aggregate in Calculation View, but still output detail field

The scenario is this:

We are joining several data sets and one has a many:many relationship. To resolve this, we will look for the oldest record. I'm able to get this to work just fine with one minor wrinkle: I still need to display the detail fields that get removed in the aggregation process in the calculation view.

Sample Data:

Material Case Date XXX 123 20130228 XXX 456 20130217 XXX 789 20130303

Customer Material Quantity ABC XXX 100 DEF YYY 75

I'm joining the material table to the transaction data, but need to pull only the oldest record. The trick is that I need to also show the case # on the oldest record. In the calculation view, if I include Case in the output, then the date field doesn't aggregate. If I remove the Case field, then it aggregates perfectly, but I'm no longer able to display case "456" in the final result set.

Anyone know of another technique that will work?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Mar 06, 2013 at 12:07 AM

    Hi Adam,

    I'm not too sure about your exact requirements, but if you're using a calculation view anyhow, you could approach this in several ways:

    1) Just write the classic SQL query for this kind of requirement.

    Something like

    select mat_cas.*from mat_cases mat_cas where mat_cas."DATE" =          (select   min ("DATE") as min_date          from mat_cases mc          where  mc.material = mat_cas.material)

    Obviously you'd have to think about what happens with rows of the same material, different case numbers and the same minimal date, but in principle this would be one option.

    2) Another way would be to create a SQLScript function that delivers the minimal date for a given MATERIAL.

    This function can then be used in a scripted calcview to mimic the behavior of the SQL above.

    For anything more specific, you'll need to tell us how your output should look like.

    - Lars

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 06, 2013 at 12:37 AM

    Hi Adam,

    May be I have not understood your scenario.

    However you want to show all the cases and just one record per material you have to preaggregate your material dimension data to store a single record per material with a concatenated string of all the case number of all the materials. There is no special functions available in HANA to achieve this on the fly however you can create procedure and loop to pre aggregate it into another table.

    Refer http://scn.sap.com/thread/3294829 how to concatenate column values across row.Once you built your pre aggregated table just create the calculation view using the new table instead.

    Hope this helps.

    Thanks!!
    Durga

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 06, 2013 at 01:22 AM

    Durga,

    No, that's not what I'm trying to do. I think Lars has understood correctly. I just want to show one result instead of 3 when I join the data sets together. Currently I'm seeing transactions repeated on the report for every instance of material. I only want to show it once, but using the oldest value.

    Unfortunately it sounds like this is not going to be possible using the graphical calculation view approach. That means I'm going to have to learn SQL (or convince someone else to do it for me) in order to get the code correct.

    Will let you know if I figure it out 😊

    Thanks!
    AZ

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.