简体   繁体   English

根据日期粒度聚合值

[英]Aggregate values according to date granularity

I am facing an issue I can't solve by my own.我面临一个我自己无法解决的问题。

I am working with time series.我正在处理时间序列。 So I have date in column.所以我在列中有日期。 The granularity can be YEAR, QUARTER & MONTH.粒度可以是年、季度和月。

I wanted to know how to display the SUM of the LASTEST MONTH of the selected date granularity.我想知道如何显示所选日期粒度的 LASTEST MONTH 的总和。

For example:例如:

If we are displaying yearly data, I would like to see, for each year, the SUM of DECEMBER data如果我们显示年度数据,我希望看到每年 12 月数据的总和在此处输入图像描述

If we are displaying quarterly data, I would like to the SUM of MARCH data for Q1, The SUM of JUNE data for Q2 and so on.如果我们要显示季度数据,我想要 Q1 的 MARCH 数据的总和,Q2 的 6 月数据的总和等等。

在此处输入图像描述

Thank you in advance for your help and feel free to ask any question if it's not clear: :)提前感谢您的帮助,如果不清楚,请随时提出任何问题::)

Regards,问候,

Maxime马克西姆

Replicating it on sample superstore将其复制到示例超市

Let's assume your desired measure is [sales].假设您想要的衡量标准是 [sales]。 Create a CF like this像这样创建一个 CF

if month([Ship Date]) =
{EXCLUDE MONTH([Ship Date]) : max( MONTH([Ship Date]))}
then [Sales] END

Add this field instead of your chosen measure on the view and Voila.在视图上添加此字段而不是您选择的度量值,瞧。

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述


As required in the comments, if only months at quarter ends are required, use this calculation field instead根据评论的要求,如果只需要季度末的月份,请改用此计算字段

if month([Ship Date]) =
{EXCLUDE MONTH([Ship Date]) : max( MONTH([Ship Date]))} 
and month([Ship Date]) IN (3, 6, 9, 12)
then [Sales] END

Check your Tableau version.检查您的 Tableau 版本。 Tableau introduced IN in its very later version. Tableau 在其最新版本中引入了IN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM