【问题标题】:Qlik line chat expressionQlik 在线聊天表情
【发布时间】:2021-10-20 09:08:29
【问题描述】:

我有一张这样的桌子

Month Customer Name Paid Collected Actual
1 John Smith 100 1000 10%
2 John Smith 200 1050 19%
3 John Smith 300 1100 27%
1 Kirk Polly 250 1150 22%
2 Kirk Polly 355 1200 30%
3 Kirk Polly 865 1250 69%

实际列的计算方法是“已收集”除以“已付费”。我想要做的是确定最大月份,因此两个客户的 int 示例都是 3,然后使用收集的最大月份金额并使用该值除以每月支付的费用。所以约翰史密斯的第 1 个月将是 300/1100,第 2 个月将是 200/1100 知道如何在折线图中执行此操作,我使用月份和客户名称作为维度绘制计算出的实际值。

提前致谢!

【问题讨论】:

  • 计算应该在脚本中还是在 UI 中?
  • 最好直接在 UI 中,即作为折线图中的表达式

标签: qlikview qliksense


【解决方案1】:

下面的注释代码将在脚本中执行计算。重新加载后,结果表将如下所示:

我会检查是否可以在 UI 中进行计算

RawData:
Load * inline [
Month,  Customer Name, Paid,    Collected,  Actual
1    ,  John Smith   , 100 ,    1000     ,  10%
2    ,  John Smith   , 200 ,    1050     ,  19%
3    ,  John Smith   , 300 ,    1100     ,  27%
1    ,  Kirk Polly   , 250 ,    1150     ,  22%
2    ,  Kirk Polly   , 355 ,    1200     ,  30%
3    ,  Kirk Polly   , 865 ,    1250     ,  69%
];

// Find the max month for each [Customer Name]
MaxMonth:
Load 
  max(Month)      as Month,
  [Customer Name]
Resident
  RawData
Group By
  [Customer Name]
;

// left join the RawData to get the Collected amount
// for the max month
// name the field MaxMonthCollected
left join 

Load 
  Month,
  [Customer Name],
  Collected      as MaxMonthCollected
Resident
  RawData
;

// join the resulted table (MaxMonth) back to RawData table
// this way agains each row we'll have the max Collected amount
// (based on the [Customer Name]
join (RawData)

Load 
  [Customer Name],
  MaxMonthCollected
Resident 
  MaxMonth
;

// We dont need this table anymore
Drop Table MaxMonth;

// Calculate "Paid / MaxMonthCollected" and name the field "Result"
// at this point the next steps might not be needed
// we have the "MaxMonthCollected" field in "RawData" table so
// we can perform the calculation in UI expression
FinalData:
Load 
  *,
  Paid / MaxMonthCollected as Result
Resident
  RawData
;

Drop Table RawData;
Drop Field MaxMonthCollected; // MaxCollected can be dropped if not needed

更新

类似下面的表达式可以直接在表格中使用。

有点警告。这是一个沉重的计算!针对大型数据集运行它可能/将导致性能问题!

sum(Paid) 
/
aggr( nodistinct
      Sum( {$< Month={"$(=aggr(Max(Month), [Customer Name]))"} > } Collected),
      [Customer Name]
)

【讨论】:

  • 非常感谢!有没有办法直接作为表达式来做到这一点?
  • 用可能的表达解决方案更新了我的答案
猜你喜欢
  • 1970-01-01
  • 2016-07-06
  • 2012-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-24
  • 2021-01-20
  • 2021-08-05
相关资源
最近更新 更多