具有多个条件的Power BI累积计数 [英] Power BI cumulative count with multiple condition

查看:2116
本文介绍了具有多个条件的Power BI累积计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何将RunningCount转换为Power bi Dax吗?
我在Rankx上的RunningTotal上进行了测试,但似乎无法正常工作。
[year]只是一个文本列,没有Datetime格式。



我对此还是很陌生,不确定我的解释是否足够好。造成不便之处,敬请原谅。



我尝试根据下面的公式在power bi中创建度量/计算列。
我需要按年份计数,并按列细分,例如产品,客户,费率和类别。

解决方案

在进入解决方案之前,我必须做一些假设:


  1. 年列应该是年,而不是五位数字。因此,在我的数据中,我在每个数据中都删除了第二个 2(即 20213-> 2013​​)。您提供的数据,无法对第一行和第三行进行排名(它们都具有乘积ABC和2003年)。

根据这些假设,这是我的解决方案...



首先,这是我的数据。我添加了一个ID列,以便我们可以看到每一行,甚至重复的行。





从那里,您可以简单地使用以下公式添加新列。

 运行次数= 
COUNTROWS(
FILTER(
'Data',
[ProductName] = EARLIER([ProductName])&&
[Customer] = EARLIER([Customer])& ;&
[卖方] = EARLIER([卖方])&&
[年]< = EARLIER([年])



Did anyone know how to convert RunningCount into Power bi Dax ? I test on RunningTotal, Rankx but seems not working. The [year] is just a text column not in Datetime format.

I still new on this and not sure if my explain is good enough or not. Sorry for any inconvenient cause.

I try to create measure/ calculation column in power bi from the formula below. I need the count by Year, break by column like product, customer, rate and category.

解决方案

Before I get into my solution, there are a few assumptions I had to make:

  1. The "Year" column is supposed to be years, and not five digit numbers. So in my data I dropped the second "2" in each (i.e. "20213" -> "2013").
  2. You may have another column in your data to break ties, but given the data you provided, there is no way to rank the first and third lines (they both have product ABC and year 2003).

Given those assumptions, here is my solution...

First, here is what my data looks like. I added an ID column so that we can see every row, even duplicates.

From there, you can simply add a new column with the following formula.

Running Count = 
    COUNTROWS(
        FILTER(
            'Data',
            [ProductName] = EARLIER([ProductName]) &&
            [Customer] = EARLIER([Customer]) &&
            [Seller] = EARLIER([Seller]) &&
            [Year] <= EARLIER([Year])
        )
    )

The EARLIER function is being used to specify a ProductName, Customer, etc. from the row of the table to be used in the filtering of the data. Once we have the data filtered, we can simple count the number of rows.

The final result looks like this. As noted in my second assumption, there is no way to break ties, so my numbers are slightly off from what you have in your screenshot

这篇关于具有多个条件的Power BI累积计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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