The question follows; however, a little setup:
--
Data
Table_S (note start of business and end of business is mentioned here for use in a related thread)
Table_analyte
Table_R
---
So the crosstab query does a wonderful job for me until now
Now I need sum(analyte_A analyte_B) and add this column (name it [A+B]) to the crosstab and it's driving me nuts.
What I tried was a modification of Allen's method (http://allenbrowne.com/ser-67.html) by creating query against Table_analyte where [analyte_pk]=1 and 2
Using that as the Cartesian product table and tried my summation...
I tried just a table with a single field and actually two records (I actually need to Sum(A,B) and Sum(A,C))
Table_sumationv alues
[A+B]
[A+C]
and two calculated fields in the crosstab as shown in AB article; however, I just couldn't get the conditional straight...
The database has thousands of samples and associated analyte/result entries....
In the past I've just exported the crosstab over to excel and manually inserted the columns I need and the sum() equation; however, I would really like to automate this so that I can go straight from the crosstab > Report > Emailed PDF
I know this is something simple I've missed.
My thought here is that I need to add these to the
Cartesian product in the CTQ
then (air code here...)
or something along those lines....
-Z
Code:
Table_Order [Order_PK] [etc...]
Code:
Table_S [s_pk] auto [fk_Order]long - related to table_order [s_name]text [s_date]date as YYYY-MM-DD hh:nn:ss [...]
Code:
Table_analyte [analyte_pk]auto [analyte_name]text
Code:
Table_R [R_pk]auto [fk_s]long - related to table_s [fk_analyte]long - related to table_analyte [r_value]double
Data
Table_S (note start of business and end of business is mentioned here for use in a related thread)
Code:
[S_pk][s_name][s_date ] [1] [s_1 ][2016-05-01 07:00:00] '(start of business day 1) [2] [s_2 ][2016-05-01 00:01:01] [3] [s_3 ][2016-05-02 06:59:59] '(END of business day 1) [4] [s_4 ][2016-05-02 07:00:00] '(start of business day 2)
Code:
[analyte_pk][analyte_name] [1 ][analyte_A ] [2 ][analyte_B ] [3 ][analyte_C ] [4 ][analyte_D ]
Code:
[R_PK][fk_s][fk_Analyte][r_value] [1 ][1 ][1 ][100 ] [2 ][1 ][2 ][200 ] [3 ][1 ][3 ][300 ] [4 ][1 ][4 ][400 ] [5 ][2 ][1 ][102 ] [6 ][2 ][2 ][202 ] [7 ][2 ][3 ][302 ] [8 ][2 ][4 ][402 ] [etc... for fk_s=3>N]
So the crosstab query does a wonderful job for me until now
Code:
[S_Name][analyte_A ][analyte_B ][analyte_C ][analyte_D ] [S_1 ][100 ][200 ][300 ][400 ] [S_2 ][101 ][201 ][301 ][401 ] [S_3 ][111 ][211 ][311 ][411 ] [etc...]
Code:
[S_Name][A+B ][analyte_A ][analyte_B ][analyte_C ][analyte_D ] [S_1 ][300 ][100 ][200 ][300 ][400 ] [S_2 ][302 ][101 ][201 ][301 ][401 ] [etc...]
Using that as the Cartesian product table and tried my summation...
I tried just a table with a single field and actually two records (I actually need to Sum(A,B) and Sum(A,C))
Table_sumationv alues
[A+B]
[A+C]
and two calculated fields in the crosstab as shown in AB article; however, I just couldn't get the conditional straight...
The database has thousands of samples and associated analyte/result entries....
In the past I've just exported the crosstab over to excel and manually inserted the columns I need and the sum() equation; however, I would really like to automate this so that I can go straight from the crosstab > Report > Emailed PDF
I know this is something simple I've missed.
My thought here is that I need to add these to the
Code:
[analyte_pk][analyte_name] [1 ][analyte_A ] [2 ][analyte_B ] [3 ][analyte_C ] [4 ][analyte_D ] [5 ][A+B ] [6 ][A+C ]
then (air code here...)
Code:
Sum(IIf([FieldName]="A+B",
(iif(analyte_pk=1,
[r_value],0)
+iif(analyte_pk=2,
[r_value],0))
[r_value])
-Z
Comment