如何在Qlik Sense中进行描述性统计

huangapple go评论55阅读模式
英文:

How to do Descriptive Statistics in Qlik Sense

问题

在Qlik Sense中如何进行描述性统计?

我指的描述性统计是在一个表格中显示均值、标准误差、中位数、众数、标准偏差、样本方差、峰度、偏度、范围、最小值、最大值、总和和计数。

在Excel中,这非常容易实现。你只需转到顶部功能区的“数据”选项卡,然后选择“数据分析”,再选择“描述性统计”。你选择输入和输出,就完成了。请查看附加的图片了解我的意思。

在Qlik Sense中,我在哪里找到这个功能呢?

英文:

How to do Descriptive Statistics in Qlik Sense? 

What I mean by Descriptive Statistics is to display Mean,  Standard Error, Median, Mode, Standard Deviation, Sample Variance, Kurtosis, Skewness, Range, Minimum, Maximum, Sum, Count in one table.

This is really easy to do in Excel. All you need to do is go to 'Data' tab on top ribbon. Then 'Data Analysis'. Then 'Descriptive Statistics'. You select the input and then output and that is it. Please see attached image to know what I mean.

Where do I find this feature in Qlik Sense?

Link to image

答案1

得分: 1

Qlik具有以下功能:

  • Sum():求和
  • Count():计数
  • Avg():平均值
  • StErr():标准误差
  • Median():中位数
  • Mode():众数
  • StDev():标准偏差
  • Sqr():平方
  • Kurtosis():峰度
  • Skew():偏度
  • Max():最大值
  • Min():最小值

关于如何应用这些函数,有三种方法:

选项 1:数据加载编辑器

您可以使用以下脚本:

[Stats]:
Load
    // [在此处分组字段...]
    Sum([MyField]) as [MyField Sum]
  , Count([MyField]) as [MyField Count]
  , Avg([MyField]) as [MyField Mean]
  , StErr([MyField]) as [MyField Standard Error]
  , Median([MyField]) as [MyField Median]
  , Mode([MyField]) as [MyField Mode]
  , StDev([MyField]) as [MyField Standard Deviation]
  , Sqr(StDev([MyField])) as [MyField Sample Variance]
  , Kurtosis([MyField]) as [MyField Kurtosis]
  , Skew([MyField]) as [MyField Snewness]
  , Max([MyField]) - Min([MyField]) as [MyField Range]
  , Min([MyField]) as [MyField Min]
  , Max([MyField]) as [MyField Max]
Resident [Transactions]
  // 按[在此处分组字段...]分组
;

选项 2:工作表 - 固定代码

您可以使用直接表格或数据透视表对象,并将所需函数作为单独的字段使用,如下所示:

  • Sum: =Sum([MyField])
  • Count: =Count([MyField])
  • Mean: =Avg([MyField])
  • Standard Error: =StErr([MyField])
  • Median: =Median([MyField])
  • Mode: =Mode([MyField])
  • Standard Deviation: =StDev([MyField])
  • Sample Variance: =Sqr(StDev([MyField]))
  • Kurtosis: =Kurtosis([MyField])
  • Snewness: =Skew([MyField])
  • Range: =Max([MyField]) - Min([MyField])
  • Min: =Min([MyField])
  • Max: =Max([MyField])

选项 3:工作表 - 动态

通过一些额外的努力,您可以使用户能够从筛选窗格中选择字段,以动态显示表中的描述性统计信息。

假设使用数据透视表,您可以使用以下表达式作为维度:

=ValueList('$(=Concat(distinct [$Field], ''', '''))')

这使用了 ValueList()Concat() 函数来从应用程序的数据模型中获取可用字段的列表。

有关更多信息,请查看上述内容中的详细解释。

英文:

Qlik has functions for each of those items:

As far as applying those functions, you can achieve this in three ways.

Option 1: Data Load Editor

You can use script like this:

[Stats]:
Load
    // [Group fields here...]

    Sum([MyField]) 		as [MyField Sum]
  , Count([MyField]) 	as [MyField Count]
  , Avg([MyField]) 		as [MyField Mean]
  , StErr([MyField]) 	as [MyField Standard Error]
  , Median([MyField]) 	as [MyField Median]
  , Mode([MyField]) 	as [MyField Mode]
  , StDev([MyField]) 	as [MyField Standard Deviation]
  , Sqr(StDev([MyField])) as [MyField Sample Variance]
  , Kurtosis([MyField]) as [MyField Kurtosis]
  , Skew([MyField])		as [MyField Snewness]
  , Max([MyField]) - Min([MyField]) as [MyField Range]
  , Min([MyField]) 		as [MyField Min]
  , Max([MyField]) 		as [MyField Max]
Resident [Transactions]
  // Group By [Group fields here...]
;

Option 2: Sheet - hard-coded

You can use a straight table or pivot table object and use the requisite functions as separate fields, like so:

  • Sum: =Sum([MyField])
  • Count: =Count([MyField])
  • Mean: =Avg([MyField])
  • Standard Error: =StErr([MyField])
  • Median: =Median([MyField])
  • Mode: =Mode([MyField])
  • Standard Deviation: =StDev([MyField])
  • Sample Variance: =Sqr(StDev([MyField]))
  • Kurtosis: =Kurtosis([MyField])
  • Snewness: =Skew([MyField])
  • Range: =Max([MyField]) - Min([MyField])
  • Min: =Min([MyField])
  • Max: =Max([MyField])

Option 3: Sheet - dynamic

With some extra effort, you can make it so that users can select fields from a filter pane to see descriptive stats in a table dynamically.

Assuming a pivot table is used, you can use this expression as the dimension:

=ValueList( '$(=Concat(distinct [$Field], ''', '''))' )

This uses the ValueList() and Concat() functions to get the list of available fields from the app's data model.

<Edit 1 for more info:>

The key here is the use of the $Field system field, which is a field that is generated automatically by Qlik whenever you reload the data model. They are "hidden" fields, so they don't show up in the Assets pane or the selections bar.

The values of the field include all available fields from the data model. We use this because we want for the user to be able to select which fields are shown in our Descriptive Stats pivot table.

Here's what the expression is doing:

  • =Concat(distinct [$Field], &#39;&#39;&#39;, &#39;&#39;&#39;) <-- Here, we are concatenating each distinct field in our data model, separating each field name with "quote, apostrophe, space, quote" like &#39;, &#39;. The reason we use three quotes together is because we want to include a quote in our resulting string so we have to escape it by using two quotes together.
  • &#39;$(= Concat(...) )&#39; <-- The Concat() function from above is "dollar sign expanded," meaning it is evaluated in-place. Note the quotes used (&#39;$(...)&#39; ) -- this means that the result of our dollar sign expansion will be a string.
  • When Qlik evaluates the above expression, it will see:
    • =ValueList( &#39;SalesAmount&#39;, &#39;MyField&#39;, &#39;Quota Number&#39;, etc. )
  • ...instead of:
    • =ValueList( &#39;$(=Concat(distinct [$Field], &#39;&#39;&#39;, &#39;&#39;&#39;))&#39; )
    • ^^That's the usefulness of the dollar sign expansion in this case.
  • The ValueList() function is used to generate a "synthetic dimension", which is essentially a on-the-fly field that is precluded from being used in selections. It's entirely ephemeral. Now, normally you cannot use this function "dynamically" -- the function expects only a list of hard-coded strings as parameters. We get around this by using the dollar sign expansion shown in the above examples.

</Edit 1>

For our measures, we'll have to use some tricky script to dynamically insert our field values. This is an example of how you could do this for the Sum() function:

=Pick(Match( ValueList( &#39;$(=Concat(distinct [$Field], &#39;&#39;&#39;, &#39;&#39;&#39;))&#39; ), &#39;$(=Concat(distinct [$Field], &#39;&#39;&#39;, &#39;&#39;&#39;))&#39;)
   , Sum([$(=Concat(distinct [$Field], &#39;]&#39; &amp; chr(41) &amp; &#39; , Sum&#39; &amp; chr(40) &amp; &#39;[&#39; ))])
)

This uses the Pick() and Match() functions to choose the correct dynamically-created Sum() function for each of our selected fields.

<Edit 2 for more info:>

Here's how this expression works:

  • The Pick(Match(...), ...) part of the expression is a way to do pattern matching in Qlik without having to use If() statements (and since switch can't be used in chart expressions). Match() returns the index of the item in a list of parameters which Pick() then uses to choose a corresponding value. In this case we use them to say, for example, "when the field name is 'SalesAmount' pick the =Sum(SalesAmount) expression; when the field name is 'MyField' pick the =Sum(MyField) expression", etc.
  • Match( ValueList( &#39;$(=Concat(distinct [$Field], &#39;&#39;&#39;, &#39;&#39;&#39;))&#39; ), &#39;$(=Concat(distinct [$Field], &#39;&#39;&#39;, &#39;&#39;&#39;))&#39;) <-- This achieves the matching behavior described above.
  • Sum([$(=Concat(distinct [$Field], &#39;]&#39; &amp; chr(41) &amp; &#39; , Sum&#39; &amp; chr(40) &amp; &#39;[&#39; ))]) <-- This expression uses dollar sign expansion (described in the Edit 1 above) to create a list of Sum() functions for each field name. So instead of:
    • Sum([$(=Concat(distinct [$Field], &#39;]&#39; &amp; chr(41) &amp; &#39; , Sum&#39; &amp; chr(40) &amp; &#39;[&#39; ))])
  • ...Qlik will see:
    • Sum([SalesAmount]), Sum([MyField]), Sum([Quota Number]), etc.

</Edit 2>

如何在Qlik Sense中进行描述性统计

You can download my example QVF file here.

huangapple
  • 本文由 发表于 2023年4月17日 16:13:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033011.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定