Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Boycie92
Resolver I
Resolver I

First and Last Date a product was bought

Hi,

 

I am hoping someone could help.

 

I have a table that contains product ID (numerous different products) and Transaction Date

 

I want to be able to identify the First Date a product was bought and the Last Date a product was bought.

 

I thought the best way to achieve this was to identify how many times that product appeared. I have this formula, it counts duplicates of Product ID as a sequence.

 

Count of Dups = CALCULATE(COUNTROWS(Table), ALLEXCEPT(Table, Table[ProductID]), EARLIEST(Table[Index]) >= Table[Index])

 

I tried to sort my table from oldest to newest and the first instance of a ProductID should be labelled as 1. However for some reason that didn’t seem to work and a newer instance was selected.

 

As for getting the last date a product was sold, I have no idea how to tackle this.

 

Any help would be appreciated and thanks in advance

 

Boycie92

 

2 ACCEPTED SOLUTIONS

Could put this in one column, but is easier to see in three: 

Earlier has the rank from earliest (1) to latest (N), Latest is reversed. 

 

Earlier = CALCULATE(COUNTROWS(Purchases),
    FILTER(ALL(Purchases), Purchases[Product] = EARLIER(Purchases[Product])&&Purchases[Purchase date] <= EARLIER(Purchases[Purchase date]))

 

Later = CALCULATE(COUNTROWS(Purchases),
    FILTER(ALL(Purchases), Purchases[Product] = EARLIER(Purchases[Product])&&Purchases[Purchase date] >= EARLIER(Purchases[Purchase date]))

 

Status = IF([Earlier]=1, "Earliest",IF([Later]=1,"Latest",BLANK()))

View solution in original post

@Boycie92

 

Hi, Please try with this Calculated Column:

 

Identifier =
VAR FirstTransactionDate =
    CALCULATE (
        FIRSTDATE ( Table1[Transaction Date] ),
        FILTER ( Table1, Table1[Product ID] = EARLIER ( Table1[Product ID] ) )
    )
VAR LastTransactionDate =
    CALCULATE (
        LASTDATE ( Table1[Transaction Date] ),
        FILTER ( Table1, Table1[Product ID] = EARLIER ( Table1[Product ID] ) )
    )
RETURN
    SWITCH (
        TRUE (),
        Table1[Transaction Date] = FirstTransactionDate, "First",
        Table1[Transaction Date] = LastTransactionDate, "Last",
        BLANK ()
    )

Result.png

 

Regards

 

Victor

Lima - Peru




Lima - Peru

View solution in original post

14 REPLIES 14

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.