Forum Discussion

mahawkins3's avatar
mahawkins3
Helper I
9 years ago
Solved

Count previous rows in table with same user ID

Hi,

I'm looking for a way to filter my datasource based on whether a customer is appearing in the table for the first time. A simplified version of the table would look something like this:

User_IDDateAmount
123401-Apr10
234501-Apr20
345602-Apr30
456702-Apr40
123403-Apr50

 

What I would like is something that looks like this, with the "New" column specifying whether a customer is appearing for the first time or not:

 

User_IDDateAmountNew
123401-Apr101
234501-Apr201
345602-Apr301
456702-Apr401
123403-Apr500

 

I could quite easily just do a count of the total number of times a customer appears in the table as a proxy, but that would break it as soon as the customer appears a second time. Is there a way to calculate this on the basis of dates? It would be so easy in Excel, but I'm not quite up to speed on DAX yet!

 

Thanks in advance,

Matt

  • mahawkins3

    You can create a Column like this

    New Column =
    IF (
        'Table'[Date]
            = CALCULATE (
                FIRSTDATE ( 'Table'[Date] ),
                ALLEXCEPT ( 'Table', 'Table'[User_ID] )
            ),
        1,
        0
    )

    Hope this helps! :smileyhappy:

     

2 Replies

  • Sean's avatar
    Sean
    Community Champion

    mahawkins3

    You can create a Column like this

    New Column =
    IF (
        'Table'[Date]
            = CALCULATE (
                FIRSTDATE ( 'Table'[Date] ),
                ALLEXCEPT ( 'Table', 'Table'[User_ID] )
            ),
        1,
        0
    )

    Hope this helps! :smileyhappy: