Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help for pivot
Message
From
17/05/2011 18:32:24
 
 
To
17/05/2011 16:29:43
Mk Sharma
Shrishti Solutions
Mumbai, India
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
01510910
Message ID:
01510929
Views:
109
This message has been marked as the solution to the initial question of the thread.
The problem is that the grand total line is calculating the sum for the rows, including the sum of your avg4 column. The following might not be exactly what you are looking for, but hopefully puts you in the right direction:
CLOSE TABLES all
 
 CREATE TABLE sampledata (party_name c(20), prod_name c(20), yearname n(4), sal_qty n(6))
 
 INSERT INTO sampledata (party_name,prod_name,yearname,sal_qty) VALUES ('PARTY A','PRODUCT A',2010,45)
 INSERT INTO sampledata (party_name,prod_name,yearname,sal_qty) VALUES ('PARTY A','PRODUCT B',2010,40)
 INSERT INTO sampledata (party_name,prod_name,yearname,sal_qty) VALUES ('PARTY A','PRODUCT A',2011,30)
 INSERT INTO sampledata (party_name,prod_name,yearname,sal_qty) VALUES ('PARTY A','PRODUCT B',2011,25)
 USE
 
 DATAPATH=SYS(5)+CURDIR()
 oExcel = createobject("excel.application")
 oExcel.Application.Visible = .T.
 oWorkbook = oExcel.Workbooks.Add()
 oTargetSheet = oWorkbook.Sheets.Add()
 oTargetRange = oTargetSheet.range("A2")
 oPivotCache = oWorkbook.PivotCaches.Add( 2 ) && external data
 oPivotCache.Connection = "OLEDB;Provider=vfpoledb.1;data source=" + DATAPATH
 oPivotCache.Commandtext = "select * from sampledata"
 oPivotTable = oPivotCache.CreatePivotTable( oTargetRange, "PivotTable" )
 oPivotTable.PivotFields("party_name").orientation = 1 && row
 oPivotTable.PivotFields("prod_name").orientation = 1 && row
 oPivotTable.PivotFields("yearname").orientation = 2 && column
 oPivotTable.PivotFields("sal_qty").orientation = 4 && data
 
 * Calculate % change
 oChangeField=oPivotTable.AddDataField(oPivotTable.PivotFields("sal_qty"), "avg4")
 oChangeField.Calculation= 3  && xlPercentOf
 oChangeField.BaseField="yearname"
 oChangeField.BaseItem="(previous)"
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform