question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question, how to divide two aggregate

See original GitHub issue

sorry, I could not find anything in the documentation how to divide two aggregate, I am using this syntax but I am stuck, all I want is to create a new aggregation new, which is the division of two aggregation sum(Installed_qty) and sum(budget)

bar = alt.Chart(df).transform_calculate(
                               new='sum(Installed_qty)'/'sum(budget)'
                                       ).mark_bar().encode(
                                   x=alt.X("date:O", timeUnit="yearmonthdate",axis=alt.Axis(format="%d %b %y")),
                                   y='new:Q'   

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jakevdpcommented, Jan 1, 2019

It’s a bit awkward in the Vega-Lite transform syntax, but you have to create two aggregate transforms and then divide them within a calculate transform. e.g.

bar = alt.Chart(df).transform_aggregate(
    sum_installed='sum(Installed_qty)',
    sum_budget='sum(budget)',
    groupby=['date']
).transform_calculate(
    new='datum.sum_installed / datum.sum_budget'
).mark_bar().encode(
    x=alt.X("date:O", timeUnit="yearmonthdate",axis=alt.Axis(format="%d %b %y")),
    y='new:Q'
)

If you’re using a pandas dataframe, it might be cleaner to add columns with the computed values.

1reaction
jakevdpcommented, Jan 1, 2019

You are applying the pts filter after the calculate and aggregate transforms, which is probably not what you want. Transforms are applied in the order they are specified.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dividing two aggregate measures
I have 2 calculations that I'm trying to divide, but it's always giving me 0. 1st calc - If Medication = "drug type...
Read more >
python 3.x - How to divide two aggreate sum dataframe
1 Answer 1 ... Your approach was correct, but you could just do the calculation inside the aggregation function only. from pyspark.sql import ......
Read more >
How to divide outputs of two fields? - Question and Answer
How to divide outputs of two fields? · count() is inside sum() , making it a nesting of aggregation · even without sum()...
Read more >
$divide (aggregation) — MongoDB Manual
Divides one number by another and returns the result. Pass the arguments to $divide in an array. ... The first argument is the...
Read more >
Table Calculations How to divide two different columns using ...
Tableau - Table Calculations How to divide two different columns using aggregate. When using measures and measure values you wont be able to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found