如何在 Power BI 中使用度量筛选折线图?
How to filter a Line Chart with a Measure in Power BI?
我目前在 Power BI 中有一个名为 Fruit
的 table。
这是来自 Fruit
的示例数据:
Issue id
Label
Label 1
Label 2
Label 3
Label 4
Created
Resolved
Time Difference (MINS)
1000
Apples
Grapes
Bananas
Oranges
Strawberries
14/03/2021 11:38:23
11/02/2022
525632
1001
Oranges
Pears
Apples
Bananas
Strawberries
13/03/2021 12:34:34
18/03/2022 11:38:23
524324
1002
Pears
Dragon Fruit
Apples
Strawberries
Dragon Fruit
04/03/2021 18:31:11
12/03/2022 11:38:23
525345
1003
Bananas
Oranges
Apples
Grapes
Pears
11/03/2021 19:34:57
11/03/2022 11:38:23
528264
1004
Grapes
Apples
Bananas
Pears
Strawberries
12/03/2021 12:32:52
15/03/2022 11:38:23
521927
我创建了一个 table 来将标签值合并为一个:
AllLabel = SUMMARIZE(UNION(VALUES(Fruit[Label 1]), VALUES(Fruit[Label 2]), VALUES(Fruit[Label 3]), VALUES(Fruit[Label 4])),Fruit[Label 1])
我还创建了一个对标签进行计数并对其进行唯一过滤的度量:
Apples
Oranges
Pears
Bananas
Strawberries
Dragon Fruit
Grapes
:
SELECTEDFruit =
var _selectedFruit = SELECTEDVALUE(AllLabel[Label 1])
return
CALCULATE(COUNTROWS(Fruit) , FILTER(Fruit,Fruit[Label 1] = _selectedFruit || Fruit[Label 2] = _selectedFruit || Fruit[Label 3] = _selectedFruit || Fruit[Label 4] = _selectedFruit))
这是 table 的样子:
我有一个折线图来计算平均解决时间:
但是,当我使用切片器选择特定水果时,它不会改变平均分辨率时间线图的值。
如何使用标签 1 切片器过滤平均分辨率折线图?
原因是你们的table没有关系。确保 table 之间存在关系。它可以是两个 table 之间的一个活动关系,您应该使用 dax 关系函数,例如 USERELATIONSHIP 公式来计算其他列之间的关系。
但是我建议使用 pivot、unpivot 和 union dax 函数来创建另一个 table 以从切片器获得最佳结果,并且不需要您的 dax 公式 AllLabel
UnpivotedTable= FILTER(
UNION(
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label]),
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label 1]),
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label 2]),
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label 3]),
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label 4])),[Label]<>"")
我目前在 Power BI 中有一个名为 Fruit
的 table。
这是来自 Fruit
的示例数据:
Issue id | Label | Label 1 | Label 2 | Label 3 | Label 4 | Created | Resolved | Time Difference (MINS) |
---|---|---|---|---|---|---|---|---|
1000 | Apples | Grapes | Bananas | Oranges | Strawberries | 14/03/2021 11:38:23 | 11/02/2022 | 525632 |
1001 | Oranges | Pears | Apples | Bananas | Strawberries | 13/03/2021 12:34:34 | 18/03/2022 11:38:23 | 524324 |
1002 | Pears | Dragon Fruit | Apples | Strawberries | Dragon Fruit | 04/03/2021 18:31:11 | 12/03/2022 11:38:23 | 525345 |
1003 | Bananas | Oranges | Apples | Grapes | Pears | 11/03/2021 19:34:57 | 11/03/2022 11:38:23 | 528264 |
1004 | Grapes | Apples | Bananas | Pears | Strawberries | 12/03/2021 12:32:52 | 15/03/2022 11:38:23 | 521927 |
我创建了一个 table 来将标签值合并为一个:
AllLabel = SUMMARIZE(UNION(VALUES(Fruit[Label 1]), VALUES(Fruit[Label 2]), VALUES(Fruit[Label 3]), VALUES(Fruit[Label 4])),Fruit[Label 1])
我还创建了一个对标签进行计数并对其进行唯一过滤的度量:
Apples
Oranges
Pears
Bananas
Strawberries
Dragon Fruit
Grapes
:
SELECTEDFruit =
var _selectedFruit = SELECTEDVALUE(AllLabel[Label 1])
return
CALCULATE(COUNTROWS(Fruit) , FILTER(Fruit,Fruit[Label 1] = _selectedFruit || Fruit[Label 2] = _selectedFruit || Fruit[Label 3] = _selectedFruit || Fruit[Label 4] = _selectedFruit))
这是 table 的样子:
我有一个折线图来计算平均解决时间:
但是,当我使用切片器选择特定水果时,它不会改变平均分辨率时间线图的值。
如何使用标签 1 切片器过滤平均分辨率折线图?
原因是你们的table没有关系。确保 table 之间存在关系。它可以是两个 table 之间的一个活动关系,您应该使用 dax 关系函数,例如 USERELATIONSHIP 公式来计算其他列之间的关系。 但是我建议使用 pivot、unpivot 和 union dax 函数来创建另一个 table 以从切片器获得最佳结果,并且不需要您的 dax 公式 AllLabel
UnpivotedTable= FILTER(
UNION(
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label]),
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label 1]),
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label 2]),
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label 3]),
SELECTCOLUMNS('Fruit',"Created",[Created],"Resolved",[Resolved],"Time Difference (MINS)",[Time Difference (MINS)],"label",[Label 4])),[Label]<>"")