Trying to create a well count to compare to BOE using the on production date and comparing it to Capital spends and total BOE - sql

I have data that includes the below columns:
Date
Total Capital
Total BOED
On Production Date
UWI
I'm trying to create a well count based on the unique UWI for each On Production Date and graph it against the Total BOED/Total Capital with Date as the x-axis.
I've tried unique count by UWI but it then populates ALL rows of that UWI with the same well count total, so when it is summed the numbers are multiplied by the row count.
Plot Xaxis as Date and Y with Total BOED and Well Count.

Add a calculated column to create a row id using the rowid() function. Then, in the calculation you already have, the one that populates all rows of the UWI with the same well count, add the following logic...
if([rowid] = min([rowid]) over [UWI], uniquecount([UWI]) over [Production Date], null)
This will make it so that the count only populates once.

Related

Calculating the percentage whilst grouping SQL

With reference to the table below, I'm suppose to group by campaign_name and media_plan_id. How can I query a table to include the percentage of a creative_names passing a threshold of 8 (banner_np_count) associated with a media_plan_id.
i.e. there are two creative names associated with some media_plan_ids, I need the percentage of total creative_names meeting the condition banner_np_count >= 8.

Microsoft Access- How to create dynamic variables that queries a selection of Columns

Example Data Picture
My main data table is constructed in the following way:
1.State
2.Product
3.Account Name
4.Jan-20
5.Feb-20
.
.
.
N.)Recent Month- Recent Year
My goal is to get 6 total sums based on 6 different contiguous that are user selected. For example, if someone wanted the value of an Account Given a State and Product for FY-2020, they would sum columns 4 to column 15 (Twelve Months).
I am going to be running joins and queries off of the State, Product, Account combinations (first three columns), but I need to create a method to sum the Data table given a list of Column Numbers.
At this point, I am not looking to put non-contiguous columns in a selected Time Period (i.e. all time period selections will be from Col.Beg_TPn to and including Col.End_TPn). The Data Table houses monthly data that will have one new column every month. The Column Number should stay consistent as we are not looking back further than FY-2020.
This a much easier problem in Excel as you can do a simple SumIfs with an Index of the Column Range as the SumRange and then you filter on Columns 1,2,3. My data table is about 30,000 rows, so Excel freezes on me when could calculations and functions on the entire data set.
What is the best way to go about this in Microsoft Access? Ideally, I would like to create a CTE_TimePeriodTotals that houses the First 3 Columns (State,Product,Account) and then 6 TP Columns (tp-1,tp-2...) that holds the sum of each time period for each row based on the Time Period Column Starts and Time Period Column End.

Pivot Table Calculated Field to Avg the Sums totaled

Need this to average = 7.41
But this happens when I use AVG
I am trying to calculate the daily average of each employee based on the number of days worked.
I already used a pivot table to calculate the daily total hours of each employee per day but I cannot figure out how to get the pivot table to display the average work day. When I alter the field settings, it averages the source data which I do not need.
The employees worked a different # of workdays, so I need the average function to calculate based on the # of instances for each employee. When I highlight the first employees data, Excel returns an average of 7.41.
Further down the list though, there are employees with 0.00 hours for a date that is beiong calculated into the averages.
How do I get this pivot table to give me a true snapshot of the persons daily hours worked - without having to manually delete 0.00 hour instances in the source data?

Calculating the rolling exponential weighted moving average for each share price over time

This question is similar to my previous one: Shifting elements of column based on index given condition on another column
I have a dataframe (df) with 2 columns and 1 index.
Index is datetime index and is in format of 2001-01-30 .... etc and the index is ordered by DATE and there are thousands of identical dates (and is monthly dates). Column A is company name (which corresponds to the date), Column B are share prices for the company names in column A for the date in the Index.
Now there are multiple companies in Column A for each date, and companies do vary over time (so the data is not predictable fully).
I want to create a column C which has the 3 day rolling exponential weighting average of the price for a particular company using the current and 2 dates before for a particular company in column A.
I have tried a few methods but have failed. Thanks.
Try:
df.groupby('ColumnA', as_index=False).apply(lambda g: g.ColumnB.ewm(3).mean())

QlikView Conditional SUM current value

I have a pivot table with multiple rows dimensions (District, Region, Shop) and months in columns. I need to calculate sales Growth ((sales this month - sales previous month)/sales previous month). As You can see from formula, i need a value from previous month (previous column). I have a formula for testing:
Sum(Total {<District={'District1'}, [Month]={'2015 09'}>} Quantity)
With this formula i am able to get the value from previous column (lets say i am calculating growth in month 2015 10 and District1). The problem is, that i get a wrong value, when this formula is used in a row with different District.
Is there any way to get district value of current row and use it in a formula? I tried multiple variations like:
Sum(Total {<District={$(District)}, [Month]={'2015 09'}>} Quantity)
Sum(Total {<District={$<=District>}, [Month]={'2015 09'}>} Quantity)
but none of them work
There is no need to add District in the calculation. QV will aggregate to it automatically since District is dimension already.
If you want to aggregate all rows under each District to show the total quantity for the whole District then you can use the following expression:
sum( total <District> Quantity )
The picture below demonstrate the result:
Also you can check the QV help (c:\Program Files\QlikView\English.chm) for the Aggr() function as well. With Aggr() function the same result can be achieved with:
aggr( NoDistinct sum( Quantity ), District )