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.  Percentage Calculation

    Employee
    Posted 04-08-2018 20:42

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

    Originally posted by: sakurasanta86

    Hi

    I have data in two cols. Col A having countries, Col B having usage. I want the Usage % in a third Col C

    I have:
    Col A Col B
    Country Usage
    Australia 20
    Singapore 10
    India 20
    USA 50
    100

    I want to see:

    Col A Col B Col C
    Country Usage %
    Australia 20 20%
    Singapore 10 10%
    India 20 20%
    USA 50 50%
    100 100%

    Thanks
    Wendy


  • 2.  RE: Percentage Calculation

    Employee
    Posted 04-09-2018 01:13

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

    Originally posted by: awilliams1024

    Here is an example calculation:

    node:Split_out_Empty_Country
    bretype:core::Split
    editor:Label=Split out Empty Country
    editor:sortkey=5acb1db116d731a0
    input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    output:@456df11556bd6bcf/=
    prop:PredicateExpr=<<EOX
    not( isNull('Col A') or trim('Col A') == "") 
    EOX
    editor:XY=460,190
    end:Split_out_Empty_Country
    
    node:Total_Usage
    bretype:core::Agg Ex
    editor:Label=Total Usage
    editor:sortkey=5acb1d1a4299280f
    input:@4b4668c040aa5a85/=Split_out_Empty_Country.40fd2c7420761db6
    output:@4b4668e708143fb4/=
    prop:GroupBy=<<EOX
    true
    EOX
    prop:Script=<<EOX
    total = groupSum('Col B')
    emit  total
    where lastInGroup
    
    EOX
    prop:SortInput=true
    editor:XY=560,230
    node:Bypass
    bretype:::Bypass
    editor:shadow=4b467f7e02db3a85
    input:@4b467f7e129d45c1/=
    input:@4b467f830ffe047b/=
    output:@40fd2c7436717256/=
    end:Bypass
    
    node:Sort
    bretype:::Sort
    editor:shadow=4b467f8972dc33df
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort
    
    node:Agg
    bretype:::Agg
    editor:shadow=4b467f9b3d5028c0
    input:@40fd2c7427456e5b/=
    output:@40fd2c744c862db0/=
    end:Agg
    
    end:Total_Usage
    
    node:Merge_in_total
    bretype:core::Lookup
    editor:Label=Merge in total
    editor:sortkey=5acb1e8064231718
    input:@40fd2c746abc6dc7/=Split_out_Empty_Country.40fd2c7420761db6
    input:@40fd2c74486e4494/=Total_Usage.4b4668e708143fb4
    output:@40fd2c7445835585/=
    prop:InputKey=<<EOX
    true
    EOX
    prop:LookupKey=<<EOX
    true
    EOX
    editor:XY=650,190
    end:Merge_in_total
    
    node:Calculate_Percentage
    bretype:core::Filter
    editor:Label=Calculate Percentage
    editor:sortkey=5acb1eaa169c3a16
    input:@40fd2c74167f1ca2/=Merge_in_total.40fd2c7445835585
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
    if isNull('Col B') then {
    	use = 0
    } else {
    	use = 'Col B'
    }
    
    p = 100*use / total
    
    emit *, p as "Col C"
    
    EOX
    editor:XY=750,190
    end:Calculate_Percentage
    
    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=5acb1ce81fc17432
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    Col A,Col B:int
    Australia,20
    Singapore,10
    India,20
    USA,50
    ,100
    EOX
    editor:XY=370,190
    end:Static_Data