Forum Discussion
Data Transformation using VBA like subtotal
- Oct 01, 2024
Hi,
As to data ETL (Extract transform and loading),another option is sql like:
select * from GenerateSubtotal limit 20;
create temp table aa as
select f03||'t' ord,'' f01,'Total' f02,f03,
colIdxf[3:6]{'' %s}, sum(f08) f08,
f09,f10,f11,f12,f13,f14,f15,f16 from GenerateSubtotal group by f03 order by ord;
create temp table bb as
select f03,group_concat(ATI) f09 from (select f03,f06,count(f06)||' site '||cast(f06*100 as text)||'% ATI '||f09 ATI from GenerateSubtotal group by f03,f06) group by f03;
create temp table cc as
select ord,f01,f02,'' f03,f04,f05,f06,f07,f08,bb.f09,f10,f11,f12,f13,f14,f15,f16 from aa join bb using(f03);
//select * from cc;
create temp table dd as
select f03 ord,* from GenerateSubtotal union all select * from cc order by ord;
select colIndex[1:] from dd;
f01 f02 f03 f04 f05 f06 f07 f08 f09 f10 f11 f12 f13 f14 f15 f16
| 9/26/2024 | a | 11 | 0.7 | 4201.22 | 1 | A | A | A | A | A | |||||
| 9/26/2024 | d | 222 | 0.5 | 4201.22 | 2 | A | A | A | A | A | |||||
| 9/26/2024 | f | 222 | 0.1 | 519 | 2 | A | A | A | A | A | |||||
| 9/26/2024 | b | 11 | 0.3 | 679 | 1 | A | A | A | A | A | |||||
| 9/26/2024 | e | 222 | 0.1 | 705 | 2 | A | A | A | A | A |
f01 f02 f03 f04 f05 f06 f07 f08 f09 f10 f11 f12 f13 f14 f15 f16
| 9/26/2024 | a | 11 | 0.7 | 4201.22 | 1 | A | A | A | A | A | ||||||
| 9/26/2024 | b | 11 | 0.3 | 679 | 1 | A | A | A | A | A | ||||||
| Total | 4880.22 | 1 site 30.0% ATI 1,1 site 70.0% ATI 1 | A | A | A | A | A | |||||||||
| 9/26/2024 | d | 222 | 0.5 | 4201.22 | 2 | A | A | A | A | A | ||||||
| 9/26/2024 | f | 222 | 0.1 | 519 | 2 | A | A | A | A | A | ||||||
| 9/26/2024 | e | 222 | 0.1 | 705 | 2 | A | A | A | A | A | ||||||
| Total | 5425.22 | 2 site 10.0% ATI 2,1 site 50.0% ATI 2 | A | A | A | A | A |