Questions tagged [calculated-columns]

A calculated column is calculated from an expression that can use other columns in the same table

A calculated column is calculated from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators. The expression cannot be a subquery.

2235 questions
4
votes
4 answers

Calculated Column Based on Two Calculated Columns

I'm trying to do a rather complicated SELECT computation that I will generalize: Main query is a wildcard select for a table One subquery does a COUNT() of all items based on a condition (this works fine) Another subquery does a SUM() of numbers in…
Jason
  • 51,583
  • 38
  • 133
  • 185
4
votes
2 answers

Computed Column (COALESCE vs CASE vs ISNULL)

I posted a similar question a while back and now as I need to update this code, I am back to ask a follow-on question. Previous question is here: Computed column based on nullable columns My data (Address1, Address2, City, State, Zip, Country) may…
Ed Sinek
  • 4,829
  • 10
  • 53
  • 81
4
votes
2 answers

Column-wise computation

I am trying to make columnwise calculations. The goal is to compute an index (IX) for for every player (r001,r002,r003), over every gameround (row). #the data frame looks like this: df <- data.frame(gameround= c("1_1", "1_2", "1_3"), r001 =…
scarlett rouge
  • 339
  • 2
  • 7
4
votes
2 answers

adding a column to df that counts occurrence of a value in another column

What I am trying to do is adding a column by "places" that count the id occurrence in the whole column "id' : id <- c(204850, 204850, 204850,312512,312512,452452,285421,758412,758412,758412) places <-…
4
votes
1 answer

Is it possible to use a subquery expression in a generated column?

I am using PostgreSQL 12, is it possible to use a query on a generated column? I mean, using in the column creation GENERATED ALWAYS AS (some query) STORED
Jorge
  • 61
  • 3
4
votes
1 answer

How can i create Generated/Computed column Postgres/DJANGO?

How can I create Generated/Computed column Postgres/DJANGO? I tried in both ways: (1) By a Class: class Product(models.Model): name = models.CharField(max_length=200, null=True) precio_costo = models.FloatField(null=True) cantidad =…
4
votes
3 answers

Pandas True False Matching

For this table: I would like to generate the 'desired_output' column. One way to achieve this maybe: All the True values from col_1 are transferred straight across to desired_output (red arrow) In desired_output, place a True value above any…
4
votes
1 answer

Hasura computed fields vs. Postgres generated columns vs. Postgres views

We're implementing an e-commerce data model and struggle to decide between Postgres generated columns, Hasura computed fields, and Postgres views. As a simplification, we have two…
Philip Seyfi
  • 929
  • 1
  • 10
  • 24
4
votes
2 answers

data.table: Create new character column based on indicator columns values and names

I have a data.table with 1.6x10^8 records and I want to create a new character column based on the indicator column names for where there is a value of 1. For example, library(data.table) DT <- data.table::data.table(ID=c("a","a","a","b","b"), …
theneil
  • 488
  • 1
  • 4
  • 14
4
votes
2 answers

SSIS fails to insert data into table that has computed column

I have an SSIS flow to insert data into a table. This flow used to work fine, until the data model was updated and a computed column was added. Now, when I attempt to load data, I get the following error: SQL Server Error Messages - Msg 271 - The…
Lee White
  • 3,649
  • 8
  • 37
  • 62
4
votes
3 answers

Average certain columns based on values in other columns

I would like to average certain column values depending on whether a condition is met in another column. Specifically, if column 1 in the below dataframe is < 1700, I want to include the corresponding value in that row from column 51 in my average…
newcoder
  • 65
  • 7
4
votes
3 answers

Pandas: How to calculate new column based on index or groupID?

This might be a very simple problem but I can not find the solution: I want to add a new column "col_new" with operations depending on group variables like groupIDs or dates. So depending on the groupID the calculation should change. Example: …
Martin Flower
  • 105
  • 3
  • 11
4
votes
2 answers

Referencing one computed column from another

I'm using SAS Enterprise Guide 7.1 and i'm having a problem with something that seems fairly basic. I'll simplify the problem but fundamentally I have one computed column (Computed_column1) that uses a CASE/WHEN statement e.g. CASE WHEN x > y THEN…
user3298004
  • 185
  • 2
  • 3
  • 10
4
votes
1 answer

Power BI - DAX measure to reference a list of values. Calculate net turnover per broker - more elegant solution?

Below is a simplified version of transaction data for stocks. StockData = DATATABLE ( "STOCK", STRING, "Date", DATETIME, "Buyer", STRING, "Seller", STRING, "Turnover", INTEGER, { { "AAPL", "2019/04/07", "GSI",…
Adni
  • 133
  • 1
  • 11
4
votes
1 answer

Check if a date column is in a range of dates - pandas

I have to check if a date column is in a range. In particular I have to check if it is included in a range given by another date +/- n days. Suppose my dataframe is: import pandas as pd d = { 'date1': ['2019-09-11', '2019-09-12', '2019-08-02'],…
stefanodv
  • 463
  • 3
  • 11
  • 20