DAX Measure 从创建的 Measure 计算 Sum 和 Count
DAX Measure to calculate Sum and Count from the created Measure
我有这样的数据,
App_Num Days Price
A1 10 100
A1 11 150
A2 11 200
A3 12 250
A3 12 300
A4 20 350
A4 21 400
现在,有一个参数供用户用来调整值并查看。
总值(最小和最大范围)
例如,如果用户选择 0-280-,则应列出 A1(100 + 150 = 250 小于 280)和 A2(200 小于 280)。
我使用了这样的 DAX,并构建了一个像这样的 table,
Apps_in_scope =
Var min_amount = Min('Total Value'[Total Value])
Var max_amount = Max('Total Value'[Total Value])
var required_app_num = SELECTEDVALUE(Table1[App_Num])
Var required_amount = CALCULATE(sum(Table1[Price]),FILTER(Table1,Table1[App_Num] = required_app_num))
var in_scope = if(And(required_amount <= max_amount, required_amount >= min_amount),1,0)
return in_scope
而且我能够制作出这样的视觉效果,
App_Num Apps_in_scope
A1 1
A2 1
A3 0
A4 0
现在,我想创建 2 个度量
- 它将列出范围内的交易总数
(A1 为 2,A2 为 1,输出到卡上的 3)。
- 它会给我卡上A1和A2的总和(100+150+200 = 450卡上)。
我该如何解决这个问题。请帮我解决这个问题。
您几乎可以像 一样处理这个问题。
使用更优化的方法:
CountInScope =
VAR apps =
ADDCOLUMNS (
SUMMARIZE (
Table1,
Table1[App_Num],
"@Rows", COUNT ( Table1[Price] )
),
"@InScope", [Apps_in_scope]
)
RETURN
SUMX ( FILTER ( apps, [@InScpoe] = 1 ), [@Rows] )
和
SumInScope =
VAR apps =
ADDCOLUMNS (
SUMMARIZE (
Table1,
Table1[App_Num],
"@Price", SUM ( Table1[Price] )
),
"@InScope", [Apps_in_scope]
)
RETURN
SUMX ( FILTER ( apps, [@InScpoe] = 1 ), [@Price] )
我有这样的数据,
App_Num Days Price
A1 10 100
A1 11 150
A2 11 200
A3 12 250
A3 12 300
A4 20 350
A4 21 400
现在,有一个参数供用户用来调整值并查看。 总值(最小和最大范围) 例如,如果用户选择 0-280-,则应列出 A1(100 + 150 = 250 小于 280)和 A2(200 小于 280)。
我使用了这样的 DAX,并构建了一个像这样的 table,
Apps_in_scope =
Var min_amount = Min('Total Value'[Total Value])
Var max_amount = Max('Total Value'[Total Value])
var required_app_num = SELECTEDVALUE(Table1[App_Num])
Var required_amount = CALCULATE(sum(Table1[Price]),FILTER(Table1,Table1[App_Num] = required_app_num))
var in_scope = if(And(required_amount <= max_amount, required_amount >= min_amount),1,0)
return in_scope
而且我能够制作出这样的视觉效果,
App_Num Apps_in_scope
A1 1
A2 1
A3 0
A4 0
现在,我想创建 2 个度量
- 它将列出范围内的交易总数 (A1 为 2,A2 为 1,输出到卡上的 3)。
- 它会给我卡上A1和A2的总和(100+150+200 = 450卡上)。
我该如何解决这个问题。请帮我解决这个问题。
您几乎可以像
使用更优化的方法:
CountInScope =
VAR apps =
ADDCOLUMNS (
SUMMARIZE (
Table1,
Table1[App_Num],
"@Rows", COUNT ( Table1[Price] )
),
"@InScope", [Apps_in_scope]
)
RETURN
SUMX ( FILTER ( apps, [@InScpoe] = 1 ), [@Rows] )
和
SumInScope =
VAR apps =
ADDCOLUMNS (
SUMMARIZE (
Table1,
Table1[App_Num],
"@Price", SUM ( Table1[Price] )
),
"@InScope", [Apps_in_scope]
)
RETURN
SUMX ( FILTER ( apps, [@InScpoe] = 1 ), [@Price] )