LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Get percentages of total value

    Employee
    Posted 06-09-2009 19:03

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: roeperg

    Hi

    I have a simple 2 column output (from a Histogram) with one column being unique. I want to see the percentage of the second column's total that each value contributes. For example, when the values are:

    Atlanta 2
    New York 2
    Tokyo 1

    I want to see:

    Atlanta .4 or 40%
    New York .4 or 40%
    Tokyo .2 or 20%

    I was trying to make the agg filter work, but I don't know how to put off outputing the results until the entire file is processed. Is there a simple or canned way to find the percentage of total?


  • 2.  RE: Get percentages of total value

    Employee
    Posted 06-10-2009 16:38

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mmarinelli

    You'll need to employ an Agg to calculate the total, and then match that total to the original data in order to calculate the percentage. The code below provides an example of this technique.

    --

    node:Agg
    bretype:core::Agg
    editor:sortkey=4a2fdfc05d864ade
    input:@40fd2c7427456e5b/=Static_Data.40fe6c55598828e5
    output:@40fd2c744c862db0/=
    prop:GroupBy=<<EOX
    1
    EOX
    prop:Script=<<EOX
    TOT = sum(CNT)

    emit *, TOT
    where lastInGroup

    EOX
    editor:XY=140,110
    end:Agg

    node:Lookup
    bretype:core::Lookup
    editor:sortkey=4a2fe03868b97532
    input:@40fd2c746abc6dc7/=Static_Data.40fe6c55598828e5
    input:@40fd2c74486e4494/=Agg.40fd2c744c862db0
    output:@40fd2c7445835585/=
    prop:InputKey=<<EOX
    1
    EOX
    prop:LookupKey=<<EOX
    1
    EOX
    prop:Script=<<EOX
    emit 1:*
    emit (1:CNT / 2:TOT) * 100 as PCT
    exclude referencedFields(2,{{^LookupKey^}})


    EOX
    editor:XY=220,60
    end:Lookup

    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=40
    end:Static_Data


  • 3.  RE: Get percentages of total value

    Employee
    Posted 06-11-2009 15:10

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: roeperg

    Great, thanks! I had actually thought of trying that but did not get around to playing with it.