Power BI cumulative count with multiple condition

送分小仙女□ 提交于 2019-12-25 18:20:02

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/55112950/power-bi-cumulative-count-with-multiple-condition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!