简体   繁体   English

Tableau 中的转义详细级别表达式

[英]Escape Level of Detail expression in Tableau

I'm trying to build a calculation that takes their values from a Parameter.我正在尝试构建一个从参数中获取它们的值的计算。 The paramater is feeded from a string dimension.参数是从字符串维度提供的。

Using SuperStore as an example, I've created a Parameter called Country Par containing all the Country/Region values.以 SuperStore 为例,我创建了一个名为Country Par的参数,其中包含所有Country/Region值。

For example, let's assume I have as a page filter Country/Region = France and the value for the Country Par = United Kingdom .例如,假设我有一个页面过滤器Country/Region = FranceCountry Par = United Kingdom的值。 Also, Month(Order Date) for Columns and Measure Values for Rows.此外,列的Month(Order Date)和行的Measure Values

The measure values selected will be:选择的测量值将是:

  • SUM(Sales)
  • SUM(Comparable Country Sales)

What I'm trying to achieve with the calculation is to retrive the values selected from the Parameter - in this case United Kingdom - ignoring whatever is selected as page filter.我试图通过计算实现的是检索从参数中选择的值 - 在本例中为英国 - 忽略选择为页面过滤器的任何内容。 (France in the example). (以法国为例)。

And the same time I want to filter the Sales for United Kingdom ending the same month as Finland.同时我想过滤与芬兰同月结束的英国销售额。

But due to the FIXED context, seems like LOD is not able to pickup the last month of Finland - Oct 2019.但由于FIXED上下文,LOD 似乎无法获取芬兰的最后一个月 - 2019 年 10 月。

Comparable Country Sales可比国家销售额

{fixed MONTH([Order Date]):
sum(
if [Country/Region]=[Country Par]
and month([Order Date]) <= {max(if [Country/Region]="Finland" then month([Order Date]) end)}
then [Sales]

else null
END)}

This is only a representation of what I want to achieve in my original datasets, for obvious reasons I can't share the data.这只是我想在我的原始数据集中实现的一个表示,原因很明显,我无法共享数据。

A few suggestions here-这里有一些建议——

  • Create another parameter for selection of different country instead of hardcoding it.为选择不同的国家/地区创建另一个参数,而不是对其进行硬编码。
  • Despite your requirement of calculation on month-wise sales/measure, do not extract month([order date]) in conditional statement because it will return only a numeric value.尽管您需要按月计算销售额/度量,但不要在条件语句中提取月份([订单日期]),因为它只会返回一个数值。 Check for date instead and later-on aggregate these month-wise if required.改为检查日期,如果需要,稍后按月汇总这些。

I have proceeded like this..我是这样进行的。。

( Note: In superstore data, I have played around on State field instead on Country as in latest version only US data is available) 注意:在超市数据中,我在 State 字段上玩过,而不是在 Country 上玩过,因为在最新版本中只有美国数据可用)

desired calculated field with calculation as desired calculated field ,计算为

{fixed DATETRUNC('month', [Order Date]):
sum(
if [State]= [Par1]
and ([Order Date]) <= {max(if [State] = [Par2] then ([Order Date]) end)}
then [Sales]
else null
END)}

See this works in my case看看这在我的情况下有效

在此处输入图像描述

Good Luck祝你好运

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

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