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.

Ability to SUM multiple columns

See original GitHub issue

Is your feature request related to a problem? Please describe. I’d like to be able to use the Sum function over multiple columns.

Example for a model

class Stats(Model):
    one_column = fields.IntField(default=0)
    two_column = fields.IntField(default=0)

I’d like to be able to do run a query like select sum(one_column+two_column) from stats

Describe the solution you’d like Stats.annotate(total_sum=Sum('one_column+two_column')) (or something similar)

Additional context

Pypika can already resolve this as seen in this test:

https://github.com/kayak/pypika/blob/16339f85ed871d937609e9dbe26487b382ca5211/pypika/tests/test_formats.py

fn.Sum(self.table_abc.fizz + self.table_abc.buzz)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
lntuitioncommented, Feb 27, 2020

@grigi Thank you so much for your discussion. I will make PR with 1 (but i’m not sure that i’m doing good. i will make WIP PR soon. Review that PR plz!) As you said, we need to think more carefully about 2 and 4.

1reaction
grigicommented, Feb 27, 2020

Yes, source_param is a prime example where we want a Model to be different compared to a legacy DB column name.

We should definitly allow F expressions in annotations. And the inverse, of annotations in .update(...) operations as well. Maybe we can get away by just making Function aware of F expressions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

sum multiple columns, how to? - Microsoft Power BI Community
Solved: Hi, Im new in powerBi and Im working in some datat wherein I need to calculate per row with multiple colums. at...
Read more >
Power BI Sum Multiple columns [With 21 Useful Examples]
To Sum Multiple columns in Power BI, we use the SUM() or SUMX() function in Power BI,. The Power BI Sum() function will...
Read more >
SUMIF multiple columns with one or several criteria in Excel
This tutorial will teach you a few easy ways to sum multiple columns in Excel based on a single or multiple criteria.
Read more >
How To Sum Columns in Excel Using Multiple Methods ...
In the "Totals" row of the table, select the cell under the column you want to sum, then use the small down arrow...
Read more >
Add Multiple Columns Using DAX In Power BI
There are two ways to achieve the same sum operation on multiple columns. Use DAX expression in a Calculated column; Use DAX expression...
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