DAX Measure 从创建的 Measure 中计算 Sum 和 Count [英] DAX Measure to calculate Sum and Count from the created Measure

查看:29
本文介绍了DAX Measure 从创建的 Measure 中计算 Sum 和 Count的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数据,

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

  1. 它将列出范围内的事务总数(A1 为 2,A2 为 1,输出到卡上的 3).
  2. 它会给我卡片上 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 Measure 从创建的 Measure 中计算 Sum 和 Count的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆