- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个事实表和一个日历表。日历表有一个 bool 列,表示一天是否是假期。
我不想创建一个度量:AllSales,它会忽略 Holiday 上的任何过滤器,但尊重所有其他 Calendar 列上的过滤器。稍后查看应用的视觉级别过滤器。
除总金额外,以下措施有效:
AllSales = CALCULATE(SUM(FactSales[Sales]); ALL('Calendar'[Holiday]); ALL('Calendar'[DateKey]))
结果见下图。个别周还可以,因为这些都可以,但请注意总和为错误总数的年份。酒吧聊天显示正确,但矩阵表中的总数是错误的。由于视觉级别筛选器 Calendar[DateKey]
移除了 2019 年的第一周,AllSales 的总数应该是 700,但它仍然计入总数。
总结一下:
Calendar[DateKey] > "2019 year 01 week
Calendar[Holiday] = False
上的视觉级别过滤器Calendar[Year]、Calendar[Week] 列排序
如果我删除 ALL(Calendar[DateKey])
它就像我的 ALL(Calendar[Holiday])
过滤器被忽略并且 AllSales
等同于原始数据列 Sales
。
如果您不想使用这里的数据,可以使用两个 M 查询来创建 Calendar 和 FactSales 表。只需通过 DateKey 1:* 单向链接它们即可。
创建两个新查询并将下面的代码粘贴到高级编辑器(M 语言编辑器)中
日历查询:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwtNQ1MAQiJR0wB0iBmCFFpalKsTpICoxQFbgl5hSjqTAmqMIEocIIuwpT3CqMDJAcamSA6VCoAiNUBViMMCaowgShAoczTLGqiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [DateKey = _t, year = _t, Week = _t, Holiday = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"DateKey", type date}, {"year", Int64.Type}, {"Week", Int64.Type}, {"Holiday", type logical}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"year", "Year"}})
in
#"Renamed Columns"
FactSales 查询:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMjIwtNQ1MAQipVgdDEEjbILG2ARNsAmaoggaGWCxCCpohE3QGJugCTZBoEWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Sales = _t, DateKey = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales", type number}, {"DateKey", type date}})
in
#"Changed Type"
我得出的结论是,DAX/TabularModel 不能很好地处理同一张表中的多个切片器/过滤器,我应该将它们分开。我仍然想知道是否有人有针对此问题的 DAX 解决方案。
最佳答案
因此,当您构建视觉对象时,会创建 DAX 查询以返回结果集,然后绘制该结果集。您可以在下面看到查询的摘录。在此之后还有更多内容,但我们拥有了解您所看到的行为所需的一切。
DEFINE
// This is a table-valued variable, which holds all dates which will be in context.
// This is based on your visual filter.
VAR __DS0FilterTable =
FILTER(
KEEPFILTERS(VALUES('Calendar'[DateKey])),
'Calendar'[DateKey] >= (DATE(2019, 1, 3) + TIME(0, 0, 1))
)
// This is a table-valued variable which holds the 1-row, 1-column table based on
// 'Calendar'[Holiday] holding the value FALSE. This is from your slicer
VAR __DS0FilterTable2 =
TREATAS({FALSE,
BLANK()}, 'Calendar'[Holiday])
// This builds up your resultset
VAR __DS0Core =
// SUMMARIZECOLUMNS lists your grouping columns, applies filters, and projects
// measures onto your resultset
SUMMARIZECOLUMNS(
// This rollup defines the grouping columns, whose values are shown on your visual.
// The rollup defines which columns get subtotals, which means we calculate an
// additional row in the resultset with filter context cleared from the column
// which is rolling up. In this case, we'll have a row with no Year context,
// but with Week context, a row with no Week context, but with Year context, and
// a row with no context on either.
ROLLUPADDISSUBTOTAL('Calendar'[Year], "IsGrandTotalRowTotal", 'Calendar'[Week], "IsDM1Total"),
// I'm separating out the filter args here. These are evaluated in a logical
// AND. The first includes all dates that pass your filter on the visual.
// The second includes only 'Calendar'[Holiday]=FALSE. The logical AND of these
// includes:
// {2019-01-04, 2019-01-05, 2020-01-02, 2020-01-03, 2020-01-04, 2020-01-05}
// Note that we're missing 2020-01-01, which passes the date test, but is a holiday.
// This is the context for evaluating our measures.
__DS0FilterTable,
__DS0FilterTable2,
// end of filter args
"Sales_Amount", 'FactSales'[Sales Amount],
"All_Sales", 'FactSales'[All Sales],
)
因此,根据评估方式,当它到达您的度量值时,日期的筛选上下文为:
<whatever is on your visual at that level>
INTERSECT
{2019-01-04, 2019-01-05, 2020-01-02, 2020-01-03, 2020-01-04, 2020-01-05}
这是我们评估的过滤器上下文:
AllSales =
CALCULATE (
SUM ( FactSales[Sales] );
ALL ( 'Calendar'[Holiday] );
ALL ( 'Calendar'[DateKey] )
)
因此,如果没有您的 ALL ( 'Calendar'[DateKey] )
,您总和的筛选上下文不包括 2020-01-01
。不幸的是,您的 'Calendar'[DateKey] > 2019-01-03
过滤器也被此 ALL
清除,这解释了您的总计问题。总计没有 Year 上下文(基于 SUMMARIZECOLUMNS
中的汇总),没有 Week 上下文(基于相同的),然后基于您的度量,没有 Holiday 上下文和 DateKey 上下文。
它适用于您的柱形图的原因是没有要显示的总计。
现在,一个可能不令人满意的解决方案是定义一个新列 YearWeek 并对其进行过滤,而不是对“日历”[DateKey] 进行过滤,因为它看起来非常相似。
所以:
//column
'Calendar'[YearWeek] = 'Calendar'[Year] * 100 + 'Calendar'[Week]
//measure:
All Sales =
CALCULATE (
SUM ( 'FactSales'[Sales] );
ALL ( 'Calendar'[Holiday] )
)
然后你可以在 'Calendar'[YearWeek] > 201901 上定义一个过滤器。这在逻辑上是等价的,但不是 DAX 等价的。您的查询现在看起来像这样:
DEFINE
// This is now on 'Calendar'[YearWeek], instead of 'Calendar'[DateKey]
VAR __DS0FilterTable =
FILTER(
KEEPFILTERS(VALUES('Calendar'[YearWeek])),
'Calendar'[YearWeek] > 201901
)
// same as before
VAR __DS0FilterTable2 =
TREATAS({FALSE,
BLANK()}, 'Calendar'[Holiday])
// Textually same as before, but different context
VAR __DS0Core =
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL('Calendar'[Year], "IsGrandTotalRowTotal", 'Calendar'[Week], "IsDM1Total"),
// Here are the filters again:
// Our intersection of 'Calendar'[Holiday]=FALSE and 'Calendar'[YearWeek]>201901.
// The 'Calendar'[YearWeek] filter is: {201902, 202001, 202002}
// so now our filter context doesn't explicitly exclude the date 2020-01-01, which
// was the problem above.
__DS0FilterTable,
__DS0FilterTable2,
// end of filters
"Sales_Amount", 'FactSales'[Sales Amount],
"All_Sales", 'FactSales'[All Sales]
)
...
基于上面的过滤器上下文,该度量工作得很好。
那么,下面两种情况有什么区别:
它们是同一张表上的两组过滤器。不同之处在于 'Calendar'[Holiday] 和 'Calendar'[DateKey] 处于同一粒度。它们的交集明确排除了您想要的日期。所以你需要一个额外的 ALL
来覆盖它。不过,ALL
过于宽泛,这会影响您的总计。
'Calendar'[Holiday] 和 'Calendar'[YearWeek] 的粒度不同。如果在单个 YearWeek 中有整整一周的天数都是“Calendar”[Holiday]=TRUE,那么您会遇到与上述相同的问题,因为“Calendar”[Holiday] 上的过滤器会无意中删除一个您要包括的整个“日历”[YearWeek]。
所有这一切的关键在于 DAX 过滤器上下文只是列中文字值的列表。重点很重要。在回答这个问题时我绞尽脑汁,但将其分解为字面值(value)表让我回到了正轨。
这是一个非常好的问题,感谢您提出这个问题。它让我深入了解了 DAX 的一些细微差别,我最近不必考虑太多。您的直觉会准确判断事物的行为方式。
关于PowerBI DAX : Creating Measure which accepts partial visual filters from same table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57957447/
我一直在尝试实现塔詹的算法来测量图中的强连通分量。既然我还没有找到任何东西,谁能提供指导,说明如何在阿帕奇时代实现塔詹的算法来测量节点之间的连通性?以下是用python编写的代码。如何使用Apache
我正在尝试更新我的一个 Android 项目的依赖项,但我收到了这个奇怪的错误。 罪魁祸首是这一行,对于 AdMob(我之前使用的是 20.6.0): implementation "com.goog
我在一个目录中有六个 .txt 文件。因此,我创建了一个变量: $foo = gci -Name *.txt $foo 现在是一个包含六个字符串的数组。就我而言,我有 PS > $foo Extens
可能已经在其他一些上下文和依赖项中询问了这个问题。 但即使花了一整天,我仍然无法弄清楚这一点。 所以下面我将完整的错误日志与我的项目级 Gradle 文件和应用级 Gradle 文件一起粘贴。 尝试运
对于我的应用程序,我需要保留用户首选的度量单位。 目前可能的单位是: 升(存储我数据库其余部分的值的单位) 千克(随产品密度变化) 美国液体加仑(3.785411784 升) 美国液体夸脱(以上的 1
我的应用程序遇到性能问题。本质上,我单击一个按钮,列表中填充了数据绑定(bind)数据(由于数据量大,这是虚拟化的),然后单击另一个按钮,该按钮将向关联的 ListView 添加一行。我含糊其词是因为
我需要将一个 Path 对象与另一个进行比较。首先,我在 onTouchEvent 的一个路径中收集所有绘制的对象: switch (event.getAction()) {
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
swift 4.2 Xcode 10β2 背景 我正在整合一个与天文学相关的 API 来处理我正在开发的应用程序中的数学运算。目的是使用 Measurement 类来处理角度和距离的输入和输出。通过这
前言 View 的工作原理中最重要的就是测量、布局、绘制三大过程,而其中测量是最复杂的; 那么我们就来介绍下View 的测量过程; 1、MeasureSpec 测量自身的大小的时候,会
我知道 getBoundingClientRect() 返回类型为 ClientRect 或 DOMRect 的对象,并且每个对象通常都具有 x、y、width、height 等。如果您 typeof
我有一个脚本来测量执行时间,但是当我使用 Measure-Command 时,我收到了似乎不准确的信息。例如,我自己为脚本计时,大约需要 15 秒才能完成。然而,这里是最后两个输出。如您所见,一个为负
我想从屏幕顶部确定元素的位置。从其他问题来看,一种方法是使用 react native 的 .measure 属性? 引用问题:React Native: Getting the position o
我编写了以下类来通过 GoogleAnalytics 测量我的服务器端流量测量协议(protocol)。 问题是所有活跃的访问者都来自我的服务器当前所在的意大利 - 我假设问题原因来自 fsockop
我想根据规则的数量和规则的复杂性来衡量流口水的表现。因此,我需要测量处理事件所需的时间。我想编写一个像这样的简单测试: long start = System.currentTimeMillis();
考虑以下代码 import numpy as np from skimage import measure def mse(x, y): return np.mean(np.square(x
什么是统一坐标测量? (厘米、米、公里) 如何在其中实现实实在在的措施? 我想在 Unity 中实现一个真正的措施。怎么做? public Vector2 GetAsMeters (Vector2 v
我正在从事一个情感分析项目,而且我是 Python 初学者。我需要计算召回率、精度和 f 度量,但我不知道数据集的语法,如下所示: #The train data format ,contains t
我正在使用 javax.measure 将用户输入转换为秒,秒数可以从秒到天不等,但是从任何单位转换为另一个单位不起作用,这是我设置的。 String units = "d"; double valu
我正在尝试开发 android 应用程序以获取有关网络信息测量的低级信息。 我想知道如何获取这些数据? 3G:-RSCP-ECNO(不是 Eclo)-BER 2G:-RxLevelQuality-Rx
我是一名优秀的程序员,十分优秀!