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
3
votes
3 answers

How to add rows in one column based on repeated values in another column , and finally keep the first row in python?

I am very new to the python pandas module. Suppose I have a data frame or table as follows: df = pd.DataFrame({ 'Column A': [12,12,12, 15, 16, 141, 141, 141, 141], 'Column B':['Apple' ,'Apple' ,'Apple' , 'Red', 'Blue', 'Yellow',…
new_bee
  • 87
  • 1
  • 8
3
votes
2 answers

R Creating new columns using vector contains name of variables

I have a data and a vector contain name of variables and i want to create new variable contain rowsum of variables in my vector, and i want the name of new variable ( sum of variables in my vector) to be concatenation of names of variables for…
Reda
  • 449
  • 1
  • 4
  • 17
3
votes
1 answer

How to get a Deterministic computed value for Date + Time

I have a table that has a datetime and a time field where the datetime is actually just the date and the time field is the time. I need to combine these 2 fields to create a "created_time" computed field. I'd like to persist this computed field but…
Brandon
  • 3,074
  • 3
  • 27
  • 44
3
votes
1 answer

Using Date Range from a Slicer in a DAX Query PowerBI

I have a date slicer that is controlled by the user. I am trying to use the users min/max date selection as a indicator. I have created two measures - one for the min value and another measure for the max value. Please see DAX code for one…
Daisy
  • 121
  • 1
  • 9
3
votes
1 answer

How to add calculated column in bigquery data table?

I am using the below code: ALTER TABLE `trim-opus-308402.Covid_Dataset_SQL_Practice_24May21.Percentage vaccine` ADD COLUMN Vaccine_Coverage numeric AS ((Rolling_vaccination / population)*100) I am getting error message: ALTER TABLE ADD COLUMN…
3
votes
3 answers

Adding column elements conditionally in R

Reproducible example: set.seed(1) testMat <- matrix(round(runif(3*6,1,5)), nrow = 3, ncol = 6) Output: [,1] [,2] [,3] [,4] [,5] [,6] [1,] 2 5 5 1 4 3 [2,] 2 2 4 2 3 4 [3,] 3 5 4 2 4 5 Here…
Rel_Ai
  • 581
  • 2
  • 11
3
votes
3 answers

How do I calculate new variables in R long tables?

I have a long table with multiple variables (CPI - Workers, CPI - Consumers, (Seas) Unemployment Level (thous) and many more, but am truncating the data set to 3 variables and 6 time periods for brevity. I want to create a new variable, which is a…
Coventure Joe
  • 149
  • 1
  • 6
3
votes
0 answers

Postgresql : syntax error at or near "(" when adding a column

I've been trying to add stored generated column with this command ALTER TABLE mtn_order ADD COLUMN textsearchable_index_col tsvector GENERATED ALWAYS AS (to_tsvector('english', coalesce(descr, '') || ' ' || coalesce(descrrep, ''))) STORED; But I…
Viktor
  • 325
  • 2
  • 10
3
votes
2 answers

Why doesn't Oracle recognize a stored generated column definition?

I have the following generated column defined within a CREATE TABLE statement: NET_ROWS_ADDED NUMBER(18) GENERATED ALWAYS AS (ROW_COUNT - PREV_ROW_COUNT) /*STORED*/, ROW_COUNT and PREV_ROW_COUNT are simple NUMBER(18) columns previously defined in…
Giffyguy
  • 20,378
  • 34
  • 97
  • 168
3
votes
2 answers

Simple calculation on array of arrays

I am having the following collection: { "price" : [ 55800000, 62800000 ], "surface" : [ 81.05, 97.4 ], } I would want to calculate the price/m2. I have tried the following but got the following…
Goul
  • 573
  • 2
  • 5
  • 16
3
votes
1 answer

creating columns using sum of existing column and looping

I am trying to generate new columns using the existing columns in the data frame. My dataframe has 60 columns . To need to generate 60 new columns based on the data in the data frame. These columns should only contain the sum. E.g Index column_a…
3
votes
1 answer

Add a computed column in Datatable based on string columns

I import data from a CSV file into a datatable. Existing vendors send period as '201901' in one column. A new vendor sends period as 2 columns like year '2019' and month 'JAN'. I want to combine the 2 columns into '201901' so that the rest of the…
Sak
  • 87
  • 6
3
votes
1 answer

Help with creating a computed column (sql server 2008)

Greetings. Need some assistance with creating a computed column on this table: USE [ScienceWorksSummary] GO /****** Object: Table [dbo].[Authors_Articles] Script Date: 04/07/2011 10:38:55 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER…
DeadDream
  • 53
  • 5
3
votes
2 answers

SQL Server: Add a column with calculated Field

I'm trying to alter a table to add an additional column that has the last 3 digits of org_id. I am doing this because software I am using cannot read 34000000000000000002 because of the size. I would like to turn 34000000000000000002 into 002 and…
Bob
  • 1,344
  • 3
  • 29
  • 63
3
votes
2 answers

Recursive CTE in Amazon Redshift

We are trying to port a code to run on Amazon Redshift, but Refshift won't run the recursive CTE function. Any good soul that knows how to port this? with tt as ( select t.*, row_number() over (partition by id order by time) as seqnum …
mfulvio
  • 33
  • 1
  • 4