Tableau计算以忽略过滤器

问题描述 投票:0回答:1

我的数据看起来像这样:

endtimestamp|account|volume|pk|var1

jan-1, conosco, 123, 13231, a
jan-1, conosco, 123, 13231, b 
jan-1, conosco, 123, 13231, c 
jan-1, acme, 1323, 2123123, a
jan-1, acme, 1323, 2123123, b
jan-1, acme, 1323, 2123123, c
jan-2, conosco, 128, 131231, a
jan-2, conosco, 128, 131231, b
jan-2, conosco, 128, 131231, c
jan-2, acme, 1329, 31323, a
jan-2, acme, 1329, 31323, b
jan-2, acme, 1329, 31323, c
...

我有一个计算来基于过滤器求和

称其为fixed_sum_volume

sum({FIXED [pk], [account]: max([volume])})

我有两个过滤器

endtimestamp

account

[选择日期范围Jan 1并选择帐户ACME

[fixed_sum_of_volume将给我日期范围的总和-1323

我需要将其除以所有时间的平均值,但我无法弄清楚如何执行此操作,或者甚至无法使用tableau。

似乎很容易,但是我已经对此进行了一段时间的努力。

总而言之,我正在寻找:

总和(已过滤量)/平均(未过滤量)

postgresql tableau tableau-server tableau-online tableau-public
1个回答
0
投票

我不知道sum(x)/ avg(y)会给您带来什么,但是下面可以完成。顺便说一句,您上面给出的值“ fixed_sum_of_volume”不正确。您有3个行用于“ acme”帐户,日期为“ Jan-1”,每个行都为1323,因此总和为3969。

with mytbl (endtimestamp,account,volume,pk,var1)  as
   ( values   (to_date('jan-1','mon-dd'), 'conosco', 123, 13231, 'a')
            , (to_date('jan-1','mon-dd'), 'conosco', 123, 13231, 'b')
            , (to_date('jan-1','mon-dd'), 'conosco', 123, 13231, 'c')
            , (to_date('jan-1','mon-dd'), 'acme', 1323, 2123123, 'a')
            , (to_date('jan-1','mon-dd'), 'acme', 1323, 2123123, 'b')
            , (to_date('jan-1','mon-dd'), 'acme', 1323, 2123123, 'c')
            , (to_date('jan-2','mon-dd'), 'conosco', 128, 131231, 'a')
            , (to_date('jan-2','mon-dd'), 'conosco', 128, 131231, 'b')
            , (to_date('jan-2','mon-dd'), 'conosco', 128, 131231, 'c')
            , (to_date('jan-2','mon-dd'), 'acme', 1329, 31323, 'a')
            , (to_date('jan-2','mon-dd'), 'acme', 1329, 31323, 'b')
            , (to_date('jan-2','mon-dd'), 'acme', 1329, 31323, 'c')
     )
select account, fixed_sum_of_volume, average_of_all_time, fixed_sum_of_volume/average_of_all_time "sum(filtered volume)/avg(non filtered volume)?"
  from 
       ( select m.account
              , sum(m.volume) filter (where to_date('jan-1','mon-dd') = m.endtimestamp) over() fixed_sum_of_volume
              , (select avg(m2.volume) from mytbl m2 where m2.account = 'acme' group by m2.account) average_of_all_time
           from mytbl m
          where m.account = 'acme' 
       ) a; 
© www.soinside.com 2019 - 2024. All rights reserved.