I'm fairly new to this, and have done a lot of searching, but I'm not even 100% sure what exactly to search for, except I know I need to use Transform.
I basically need this:
Column A Column B
Total 184
Half 20
Some 25
None 30
Total 52
Half 25
Some 16
None 86
To become:
Total Half Some None
184 20 25 30
52 25 16 86
Any help would be amazing, it's the last part of a query, then it's done.
Thanks :)
The answer ended up being something like this. Don't do it with the Query Wizard, it won't work out very well. This is Access 2010.
TRANSFORM First(Table.ColumnB) AS FirstOfColumnB
SELECT Table.Columns
FROM Table
GROUP BY Table.Columns
PIVOT Table.ColumnA;
Related
So maybe I'm just way over-thinking things, but is there any way to replicate a nested/loop calculation in Vertica with just SQL syntax.
Explanation -
In Column AP I have remaining values per month by an attribute key, in column CHANGE_1M I have an attribution value to apply.
The goal is for future values to calculate the preceding Row partition AP*CHANGE_1M, by the subsequent row partition CHANGE_1M to fill in the future AP values.
For reference I have 15,000 Keys Per Period and 60 Periods Per Year in the full-data set.
Sample Calculation
Period 5 =
(Period4_AP * Period5_CHANGE_1M)+Period4_AP
Period 6 =
(((Period4_AP * Period5_CHANGE_1M)+Period4_AP)*Period6_CHANGE_1M)
+
((Period4_AP * Period5_CHANGE_1M)+Period4_AP)
ect.
Sample Data on Top
Expected Results below
Vertica does not have (yet?) the RECURSIVE WITH clause, which you would need for the recursive calculation you seem to be needing here.
Only possible workaround would be tedious: write (or generate, using perl or Python, for example) as many nested queries as you need iterations.
I'll only want to detail this if you want to go down that path.
Long time no see - I should have returned to answer this question earlier.
I got so stuck on thinking of the programmatic way to solve this issue, I inherently forgot it is a math equation, and where you have math functions you have solutions.
Basically this question revolves around doing table multiplication.
The solution is to simply use LOG/LN functions to multiply and convert back using EXP.
Snippet of the simple solve.
Hope this helps other lost souls, don't forget your math background and spiral into a whirlpool of self-defeat.
EXP(SUM(LN(DEGREDATION)) OVER (ORDER BY PERIOD_NUMBER ASC ROWS UNBOUNDED PRECEDING)) AS DEGREDATION_RATE
** Controlled by what factors/attributes you need the data stratified by with a PARTITION
Basically instead of starting at the retention PX/P0, I back into with the degradation P1/P0 - P2/P1 ect.
PERIOD_NUMBER
DEGRADATION
DEGREDATION_RATE
DEGREDATION_RATE x 100000
0
100.00%
100.00%
100000.00
1
57.72%
57.72%
57715.18
2
60.71%
35.04%
35036.59
3
70.84%
24.82%
24820.66
4
76.59%
19.01%
19009.17
5
79.29%
15.07%
15071.79
6
83.27%
12.55%
12550.59
7
82.08%
10.30%
10301.94
8
86.49%
8.91%
8910.59
9
89.60%
7.98%
7984.24
10
86.03%
6.87%
6868.79
11
86.00%
5.91%
5907.16
12
90.52%
5.35%
5347.00
13
91.89%
4.91%
4913.46
14
89.86%
4.41%
4414.99
15
91.96%
4.06%
4060.22
16
89.36%
3.63%
3628.28
17
90.63%
3.29%
3288.13
18
92.45%
3.04%
3039.97
19
94.95%
2.89%
2886.43
20
92.31%
2.66%
2664.40
21
92.11%
2.45%
2454.05
22
93.94%
2.31%
2305.32
23
89.66%
2.07%
2066.84
24
94.12%
1.95%
1945.26
25
95.83%
1.86%
1864.21
26
92.31%
1.72%
1720.81
27
96.97%
1.67%
1668.66
28
90.32%
1.51%
1507.18
29
90.00%
1.36%
1356.46
30
94.44%
1.28%
1281.10
31
94.12%
1.21%
1205.74
32
100.00%
1.21%
1205.74
33
90.91%
1.10%
1096.13
34
90.00%
0.99%
986.52
35
94.44%
0.93%
931.71
36
100.00%
0.93%
931.71
I am relatively new to this field and am working with a data set to find meaningful insights into customer behavior. My dataset looks like:
customerId week first_trip_week rides
0 156 44 36 2
1 164 44 38 6
2 224 42 36 5
3 224 43 36 4
4 224 44 36 5
What I want to do is create new columns week 44,week 43, week 42 and get the values in the "ride" column to be filled into the rows for the respective customer id. This is in the hope that I can eventually also make the customerId my index and can get denominations for different weeks. Help would be greatly appreciated!
Thank you!!
If I'm understanding you correctly, you want to create new columns in the same dataframe for weeks 44, 43, and 42 with the correct values for each customerId and NaN for those that don't have it. If your original dataframe has all the user data, I would first filter for dataframes that have the correct week number
week42DF = dataset.loc[dataset['week']==42,['customerId','rides']].rename(columns={'rides':'week42Rides'})
getting only the rides and customerId and renaming the former here to make things a little easier for us. Then left join the old dataframe and the new one on customerId
dataset = pd.merge(dataset,week42DF,how='left',on='customerId')
The users that are missing from week42DF will have NaN in the week42rides column in the merged dataset which you can then use the .fillna(0) method to replace with zeros. Do this for each week you require.
See Pandas' documentation on merge and the more general concatenate for more info.
I have one SQL table with the data in SAS. The first column is a datetime, and there is one row for each second. The set spans for about 20 minutes. The other columns contain integer values.
Here is what I need:
For example, Let's pick 50. How many times did the integer value go from below 50 to above 50 and stay above 50 for at least n seconds.
Is it possible to conduct such analysis with proc sql? If yes, how so, and if not, how else?
I am new to SAS, so any help is appreciated. Let me know if you need more info!
Thanks!
How many times did the integer value go from below/above 50
I think this could be solution to first part of the question. Resolution is maybe the best obtained by comparing current value with prior
data begin; /*Some test data...*/
input int_in_question;
datalines;
51
51
49
55
55
40
40
60
40
;
run;
data With_calc;
set begin;
if int_in_question < 50 and
lag(int_in_question)>=50
then Times_below_50+1;
run;
I have a lot of data for each User ID that needs to be organized by column rather than by row as it is currently. I have tried standard transposition methods but cannot figure this out. Any ideas would be greatly appreciated.
Current data set:
UserId Item Value(mL)
1 AAA 12
1 AAB 21
1 AAC 31
2 AAA 15
2 AAB 21
2 AAC 34
2 AAD 16
Desired outcome:
UserID AAA AAB AAC AAD
1 12 21 31
2 15 21 34 16
With formula:
=SUMIFS($C:$C,$A:$A,$F2,$B:$B,G$1)
Copy over and down.
As #skkakkar stated: with Pivot Table
There is an excel paste option called "transpose" that will allow you to accomplish this. Select your data and copy it. Then go to the target cell and go to paste options and press "T" or click the transpose button.
EDIT:
There are other ways of solving this, as Scott has shown in his answer. If you are performing this on a large data set, my solution will be the fastest by far, but his solution is also very sleek. In addition, this won't work to only keep non-duplicate headers. You will need to do a bit of work to have this work the exact way the poster wanted.
I am a newbie in SSAS, I have encountered a minor issues in cube and I cant solve it in many days
Please help me this, I very appreciate your ideas.
My cube has a measure that shows the percentage.
The percentage does not displays correctly when we use filter.
For example:
*** Without filter any dimensions, it is correct
Age Percentage
15 - 24 11.64%
25 - 24 24.21%
35 - 44 24.03%
45 - 54 20.17%
55 - 64 12.92%
65+ 6.66%
Do not know 0.38%
Grand Total 100.00%
*** With filter Gender=Male (or any dimensions), it likes this.
Age Percentage
15 - 24 4.72%
25 - 24 13.55%
35 - 44 15.87%
45 - 54 13.52%
55 - 64 8.07%
65+ 3.66%
Do not know 0.18%
Grand Total 59.58%
what I expect that it should be 100% in Grand Total and the percentage of each category must be recalculated.
Please help me !!!