DAX度量以根据创建的度量计算总和和计数 [英] DAX Measure to calculate Sum and Count from the created Measure
本文介绍了DAX度量以根据创建的度量计算总和和计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的数据
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).
Now, there is a parameter that the user uses to adjust the values and see. Total Value (Min and Max Range) For example, if the user selects 0-280- it is expected to list A1 (100 + 150 = 250 less than 280) and A2 (200 being less than 280).
我使用了这样的DAX并建立了这样的表格,
I used a DAX like this and built a table like this,
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
我能够产生这样的视觉效果
And I was able to produce a Visual like this,
App_Num Apps_in_scope
A1 1
A2 1
A3 0
A4 0
现在,我要创建2个度量
Now, I want to create 2 Measures
- 它将列出范围内的交易总数(对于A1是2,对于A2是1,输出到卡上的3).
- 它将给我卡片上的A1和A2之和(卡片上100 + 150 + 200 = 450).
我该如何处理.请帮助我.
How do I approach this. Kindly help me with this.
推荐答案
您几乎可以像上一个问题一样处理此问题.
You can approach this almost exactly like your previous question.
使用更优化的方法:
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] )
这篇关于DAX度量以根据创建的度量计算总和和计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文