PowerBI DAX - Identifying first instance based on multiple criteria

前端 未结 1 448
余生分开走
余生分开走 2021-01-26 00:10

Using DAX to identify first instance of a record

I\'m faced with trying to identify the first instance in a database where someone (identified by the ID column) has pu

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-26 00:55

    This is very similar to an answer I gave to another question (which you can find here).

    In that question, the request was to see a running count of rows for the given row's criteria (product, year, etc.). We can modify that slightly to get it to work in your problem.

    This is the formula I provided in the answer I linked above. The basic concept is to use the EARLIER functions to get the value from the row and pass it into the filter statement.

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

    What I would suggest for your problem is to create this as a TRUE/FALSE flag by simply checking if the running count is 1. This formula will evaluate to a Boolean flag.

    First Instance = 
        COUNTROWS(
            FILTER(
                'Data',
                [ID] = EARLIER([ID]) &&
                [Product] = EARLIER([Product]) &&
                [Purchase Date] <= EARLIER([Purchase Date])
            )
        ) = 1
    

    0 讨论(0)
提交回复
热议问题