在DAX上使用更多过滤器

发布于 2025-01-29 20:41:06 字数 1526 浏览 1 评论 0 原文

再会!

请求

以下是我的原始数据,并应用了一些条件以检查需要计算哪些列。

示例:

  • 第1行,方向是导出,部门代码没有以“ D”开头 将计算所有6列(ETD,ATD,ETA,ATA,估计的Delivey,
    实际交货),只填充了5个,因此获得83个
    百分比。
  • 第2行,方向是出口,部门代码开始 使用“ D”,只会计算4列(ETA,ATA,估计的交付 和实际交付),只填充了2个,因此获得50%。

我现在拥有的:

我有一个代码,但它仅显示所有列,并且填充了哪个列,我希望在计算上述条件方面有所帮助。

dax :(计算不是空白)

Count = 
SUMX(
ADDCOLUMNS(
RawData,
"Count",
var tab = {RawData[ETD],RawData[ATD],RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]}
var result = 
COUNTROWS(
FILTER(
tab,
[Value]<>BLANK()))
return
IF(
ISBLANK(result),
0,
result
 ) ),[Count])

dax:计算空白

Count = 
SUMX(
ADDCOLUMNS(
RawData,
"Count",
var tab = {RawData[ETD],RawData[ATD],RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]}
var result = 
COUNTROWS(
FILTER(
tab,
[Value]=BLANK()))
return
IF(
ISBLANK(result),
0,
result
 ) ),[Count])

将不胜感激。

与我的pbix相连:

谢谢!

Good Day!

Request
enter image description here

The following is my raw data, with some conditions applied to check which columns need to be counted.

Example:

  • Row 1, direction is export, department code is not starting with 'D',
    will count all 6 columns (ETD, ATD,ETA, ATA, Estimated Delivey,
    Actual Delivery) , and only 5 have been filled in, so get 83 as the
    percentage.
  • Row 2, direction is export, department code starting
    with 'D', will only count 4 columns (ETA, ATA,Estimated Delivery
    and Actual Delivery), and only 2 has been filled in, so get 50%.

What I have now:
enter image description here

I have a code but it only shows all columns and which column has been filled, and I would like some help in calculating the conditions as stated above.

DAX: (calculate not blank)

Count = 
SUMX(
ADDCOLUMNS(
RawData,
"Count",
var tab = {RawData[ETD],RawData[ATD],RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]}
var result = 
COUNTROWS(
FILTER(
tab,
[Value]<>BLANK()))
return
IF(
ISBLANK(result),
0,
result
 ) ),[Count])

DAX: Calculate blank

Count = 
SUMX(
ADDCOLUMNS(
RawData,
"Count",
var tab = {RawData[ETD],RawData[ATD],RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]}
var result = 
COUNTROWS(
FILTER(
tab,
[Value]=BLANK()))
return
IF(
ISBLANK(result),
0,
result
 ) ),[Count])

Any help will be greatly appreciated.

Attached here with my pbix: https://drive.google.com/file/d/1KIROrAzNEp710JEfxMfiZLzvTpuHj3OZ/view?usp=sharing

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2025-02-05 20:41:06

对于计数,我添加了“ D”的决策;

Count = 
SUMX(
    ADDCOLUMNS(
        RawData,
        "Count",
        var Dep = RawData[Dep]
        var res1 = COUNTROWS(
            FILTER(
                {RawData[ETD],RawData[ATD],RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]},
                NOT ISBLANK([Value])
            )
        )
        var res2 = COUNTROWS(
            FILTER(
                {RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]},
                NOT ISBLANK([Value])
            )
        )
        
        return  if (LEFT(Dep, 1) = "D", res1, res2)
    ),
    [Count]
)

我还遵循您的逻辑进行计数量度:

Counts = 
SUMX(
    ADDCOLUMNS(
        RawData,
        "Count",
        var Dep = RawData[Dep]
        var res1 = COUNTROWS(
            FILTER(
                {RawData[ETD],RawData[ATD],RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]},
                ISBLANK([Value])
            )
        )
        var res2 = COUNTROWS(
            FILTER(
                {RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]},
                ISBLANK([Value])
            )
        )
        
        return  if (LEFT(Dep, 1) = "D", res1, res2)
    ),
    [Count]
)

然后,我添加了度量%

% = RawData[Count]/RawData[Total]

结果:

我相信您会更好地使用计算的列,但没有像您选择的措施那样去做。

如果我会从头开始,我将使用一个Undivot表中的Power查询,这使编码更加动态

For the count I added the decision making of the "D";

Count = 
SUMX(
    ADDCOLUMNS(
        RawData,
        "Count",
        var Dep = RawData[Dep]
        var res1 = COUNTROWS(
            FILTER(
                {RawData[ETD],RawData[ATD],RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]},
                NOT ISBLANK([Value])
            )
        )
        var res2 = COUNTROWS(
            FILTER(
                {RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]},
                NOT ISBLANK([Value])
            )
        )
        
        return  if (LEFT(Dep, 1) = "D", res1, res2)
    ),
    [Count]
)

I also followed your logic to go with the Counts measure:

Counts = 
SUMX(
    ADDCOLUMNS(
        RawData,
        "Count",
        var Dep = RawData[Dep]
        var res1 = COUNTROWS(
            FILTER(
                {RawData[ETD],RawData[ATD],RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]},
                ISBLANK([Value])
            )
        )
        var res2 = COUNTROWS(
            FILTER(
                {RawData[ETA],RawData[ATA],RawData[Estimated Delivery],RawData[Actual Delivery]},
                ISBLANK([Value])
            )
        )
        
        return  if (LEFT(Dep, 1) = "D", res1, res2)
    ),
    [Count]
)

Then I added the measure %

% = RawData[Count]/RawData[Total]

Result:
enter image description here

I do believe you would be better of using calculated columns but did not go their as you had choosen measures already.

IF I would have started from scratch, I would have gone with an unpivot table in power query what makes the coding more dynamic

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文