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
win_anthony
Resolver III
Resolver III

Most Recent Transaction Per Store

The goal is to flag only the most recent transaction per store. My current output will flag the most recent transaction for each unique transaction. The requirements changed and I need to flag only the most recent transaction but can't figure out to only get the most recent transaction regardless of any other transactions. For context, below is: current measure / sample data table = current output / sample data = expected output. 

Any advice on how I can flag only the most recent transaction per store? 

Current Measure

 

 

Latest Transaction = 
IF(
    Transactions[Date]
    = CALCULATE(
        MAX( Transactions[Date] ),
        ALLEXCEPT( Transactions, Transactions[Transaction_ID] )
    ), 1
)

 

 

Current Output = Sample Data Table

Transaction_IDStore_NumStatusDateLatest_Transaction
1015New1-Jan-21 
1015In Process2-Jan-21 
1015Complete3-Jan-211
1025New1-Jan-211
1035New12-Jan-21 
1035In Process28-Feb-211
1045New25-Jan-21 
1045In Process26-Jan-21 
1045Deleted27-Jan-211

Expected Output = Sample Data Table

Transaction_IDStore_NumStatusDateLatest_Transaction
1035In Process28-Feb-211

 

Your advice is greatly appreciated. 

1 ACCEPTED SOLUTION

@win_anthony

Measure 2 = IF (
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            VALUES ( 'Table'[Date] ),
            'Table'[Date] = CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[store]))
        )
    )
        <> BLANK (),
    "latest"
)

Capture.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
smpa01
Super User
Super User

@win_anthonycan you try this measure

 

Measure :=
IF (
    CALCULATE (
        MAX ( 'Table 1'[Date] ),
        FILTER (
            VALUES ( 'Table 1'[Date] ),
            'Table 1'[Date] = CALCULATE ( MAX ( 'Table 1'[Date] ), ALL ( 'Table 1' ) )
        )
    )
        <> BLANK (),
    "latest"
)

 

Capture.PNG

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01  Thank you so much for your support! This is pretty much spot on for what I am looking for. Question for you though. If I wanted to do this same action but apply it to every store, how would you update this measure? My sample data only reflected 1 store. Let's assume that there are 5,000 stores and you wanted to reflect the most recent transaction for each store. How would you update this measure? The output when I dropped your suggestion into my model gave me the most recent transaction but only reflected 1 store when the goal is to reflect the most recent transaction for all stores. 

 

Ex: 5,000 stores = 5,000 most recent transactions output

@win_anthony

Measure 2 = IF (
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            VALUES ( 'Table'[Date] ),
            'Table'[Date] = CALCULATE(MAX('Table'[Date]),ALLEXCEPT('Table','Table'[store]))
        )
    )
        <> BLANK (),
    "latest"
)

Capture.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Do you have a dimensional model with a dimension table for stores? If not, you should create one. Read my article here https://exceleratorbi.com.au/the-optimal-shape-for-power-pivot-data/

you need dimensions for customer, transaction id and date (minimum)

 

Assuming you have a dim model, the following measure should return the last transaction date into a table visual of store IDs coming from the dimension table. 

 

Last transaction date = max(trans[date])


Assuming there is only 1 transaction id per day (or the transaction IDs increment in value over time) the following will return the id as a measure. 

last transaction id = calculate(max(trans[id]),all(calendar[date]))

 

If you then add the transaction id from the dim table to the table containing the customer id, the following measure should force only those transactions to show.


Show Transaction = If(SELECTEDVALUE(trans[id])=[last transaction id],1)

 

i have not tested any of this as you have not provided any test data. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

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.