首页 文章

DAX:使用度量结果填充计算列而不重新计算每行的度量

提问于
浏览
0

我希望有人可以提供帮助,因为我已经把头发拉了几个小时......我在PowerBI上有两张 table . 一个名为'Fact_WorstInstance'的行包含(Index,Instance)行 . 例如:

1,2
2,1
3,2

一个名为'Fact_AllInstances'的行包含(Index,Instance,Value)行 . 例如:

1,1,'Red'
1,2,'Green'
2,1,'Amber'
2,2,'Red'
2,3,'Brown'
3,1,'Green'
3,2,'Blue'

第一个表基本上是指向给定索引的第二个表中最差条目的指针(由某些外部系统分类) .

有一个切片器,索引对用户可见 .

我想要做的是在'Fact_WorstInstance'表中找到最高可见索引的最差实例值,然后从该实例的'Fact_AllInstances'表中获取所有Index和Value行 .

例如,如果切片器没有过滤,则(3,2)应该是来自'Fact_WorstInstance'表的活动行,这应该用于从'Fact_AllInstances'表中获取实例2

1,2,'Green'
2,2,'Red'
3,2,'Blue'

来自'Fact_AllInstances'表 .

我尝试通过在'Fact_WorstInstance'上创建一个度量来提供最高可见行,以多种方式实现此目的 . 然后使用此度量在'Fact_AllInstances'上创建计算列,其中1表示最差,0表示非最差 . 然后使用此计算列作为PowerBI中的过滤器 .

度量本身给出了期望值 . 我遇到的问题是当度量用于创建计算列时,我找不到根据计算列的行停止索引的方法 - 因此每行的度量结果都会发生变化 .

我的措施:

Worst Entry = CALCULATE(FIRSTNONBLANK(Fact_WorstInstance[Instance],1),filter(ALLSELECTED(Fact_WorstInstance),Fact_WorstInstance[Index]=MAX(Fact_WorstInstance[Index])))

我的专栏:

WorstColumn = if(Fact_AllInstances[Instance]=[Worst Entry],1,0)

所以我没有得到上面的输出

1,2,'绿色'2,1,'琥珀' - >因为对于指数2,该指标给出指数1为最差3,2,'蓝'

任何帮助将不胜感激 . 谢谢Rich

1 回答

  • 1

    这是您可能想要实现的可能解决方案 .

    首先,计算列不受切片器/页面过滤器的影响,您需要为此创建一个度量,因此您应用问题的方式将无法正常工作 .

    创建一个包含唯一实例值的附加计算表 . 在Power BI,Modeling选项卡中,有一个用于创建 New Table 的图标,您可以使用表达式生成表格 .

    使用此表达式:

    IsntancesCalcTable = VALUES(Fact_WorstInstance[Instance])
    

    现在,您的模型中有一个名为 InstancesCalcTable 的表 .

    拖动 InstancesCalcTable 中的 Instance 列并将其放在 Fact_WorstInstanceInstance 列中,这将通过 InstanceInstancesCalcTableFact_WorstInstance 之间创建关系 . 两个表之间的一条线将在 Relationships 视图中绘制,双击该行,您将看到 Edit Relationship 窗口 .

    确保它看起来像这样:

    enter image description here

    然后执行相同的操作以创建 InstancesCalcTableFact_AllInstances 之间的关系 .

    你将以这样的模型结束:

    enter image description here

    然后,您可以在 Fact_WorstInstance 表中使用 Index 列,在切片器中它将过滤 Fact_AllInstances 表以仅获取所选实例 .

    enter image description here

    但是,如果您没有任何过滤器,则会显示 Fact_AllInstances 中的所有行 .

    如果这有帮助,请告诉我 .

相关问题