Crystal Reports 13带有公式字段的标准偏差

时间:2016-06-30 13:42:34

标签: crystal-reports stdev

我一直致力于使用StDev功能的其他人做出的报告。我认为这很简单,但数据可以包含每个记录的多个值,因此有if语句用于确定从每个记录中取出哪个值。我已经将表格导出到Excel,每个记录包含一个值(应该在StDev中使用的值),然后在那里计算SD以提供检查。

报告和Excel给出了非常不同的价值观:(

所以,我回到报告中并使用一些额外的公式字段来计算SD缩写以作为一种决定性投票(手指越过它并不会产生第三组值。 ..)。

我已经解决了语法错误,但仍然遇到了运行时错误 - "除以零"然后突出显示下面的代码部分......

我的公式字段是:

{@ StDevArrayPopulate} - 在详细信息部分

                                                                         java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.enxin.crystallise/com.example.enxin.crystallise.MainActivity}: android.database.sqlite.SQLiteException: no such column: thoughts (code 1): , while compiling: SELECT _id, title, message, thoughts, category, date FROM note
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:135)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                             at android.os.Looper.loop(Looper.java:136)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                             at java.lang.reflect.Method.invokeNative(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:515)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                             at dalvik.system.NativeStart.main(Native Method)
                                                                          Caused by: android.database.sqlite.SQLiteException: no such column: thoughts (code 1): , while compiling: SELECT _id, title, message, thoughts, category, date FROM note
                                                                             at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                                             at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                                                                             at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
                                                                             at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                                             at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
                                                                             at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
                                                                             at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
                                                                             at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
                                                                             at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
                                                                             at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
                                                                             at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
                                                                             at com.example.enxin.crystallise.NotebookDbAdapter.getAllNotes(NotebookDbAdapter.java:98)
                                                                             at com.example.enxin.crystallise.MainActivityListFragment.onActivityCreated(MainActivityListFragment.java:39)
                                                                             at android.app.Fragment.performActivityCreated(Fragment.java:1708)
                                                                             at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:908)
                                                                             at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
                                                                             at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1044)
                                                                             at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1853)
                                                                             at android.app.Activity.performCreate(Activity.java:5234)
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:136) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                             at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
                                                                             at dalvik.system.NativeStart.main(Native Method) 

{@ StDevArrayCalculate} - 在组页脚

NumberVar Array varStDevArray;
NumberVar varStDevArrayCount;

varStDevArray [varStDevArrayCount] := {ValueToSummarise};

varStDevArrayCount := varStDevArrayCount + 1;

{@ StDevArrayCalculate} - 在组页脚

NumberVar Array varStDevArray;
NumberVar varCounter :=1;
NumberVar varMean := 0;
NumberVar varStDev := 0;
NumberVar varStDevArrayCount;

// START OF MEAN

// Sum of all of the values in the array

for varCounter:= 1 to varStDevArrayCount step 1 do
(
    varMean := varMean + varStDevArray [varStDevArrayCount];
);

// Divide by the total number of values in the array

varMean := varMean / varStDevArrayCount;  // !! This is the line that highlights after the error message !!

// END OF MEAN

// START OF STANDARD DEVIATION

// Subtract the mean from each value in the array and square the result

for varCounter := 1 to varStDevArrayCount step 1 do
(
    varStDevArray[varStDevArrayCount] := (varStDevArray [varStDevArrayCount] - varMean) * (varStDevArray [varStDevArrayCount] - varMean);
);

// Sum of all of the values in the array

for varCounter:= 1 to varStDevArrayCount step 1 do
(
    varStDev := varStDev + varStDevArray [varStDevArrayCount];
);

// Divide by the total number of values in the array

varStDev := varStDev / varStDevArrayCount;

// Square root of mean of differences

varStDev := Sqr(varStDev)

// END OF STANDARD DEVIATION

我尝试过使用“运行总计”字段但由于需要在填充“填充公式”字段之前计算第一条记录,因此会产生错误。我还尝试在标题中添加第四个字段,将varStDevArrayCount初始化为1。

有人有任何建议吗?

1 个答案:

答案 0 :(得分:0)

看起来没有详细记录,因此您在数组中得到零...我不认为使用1初始化会产生任何差异,而是进行如下所示的小改动并检查。

if varStDevArrayCount=0
then
varMean :=varMean 
else
varMean := varMean / varStDevArrayCount;

我建议你只是详细检查记录,然后调试