cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper I
Helper I

Getting max date and then an accompanying column

Hello everyone

 

I have a table where I have captued the customer ID and the list of products they purchased and when (date/time).

From this I want to know which was the last product they purchased.

 

But I cannot seem to figure out the method to extract this result.

Here is what my data looks like and the expected result.

Kindly assist.

 

Untitled.png

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: Getting max date and then an accompanying column

@fahadarshad

 

If you need a Table

 

Go to Modelling Tab>>>NEW TABLE and then use this formula.

 

 

New Table =
SUMMARIZE (
    TableName,
    TableName[Customer ID],
    "Last Date", MAX ( TableName[Date] ),
    "Last Product", CALCULATE (
        FIRSTNONBLANK ( TableName[Product], 1 ),
        FILTER ( TableName, TableName[Date] = MAX ( TableName[Date] ) )
    )
)
Regards,
Zubair


View solution in original post

11 REPLIES 11
Highlighted
Super User III
Super User III

Re: Getting max date and then an accompanying column

@fahadarshad

 

Try these MEASURES. Then in a Table Visual drag the Date Column and these 2 Measures

 

 

 

LastDate = Max(TableName[Date])
LastProduct =
CALCULATE (
    FIRSTNONBLANK ( TableName[Product], 1 ),
    FILTER ( TableName, TableName[Date] = [LastDate] )
)
Regards,
Zubair


Highlighted
Helper I
Helper I

Re: Getting max date and then an accompanying column

Hi Zubair @Zubair_Muhammad

 

What about the customer ID. how do I get that in as well.

Highlighted
Super User III
Super User III

Re: Getting max date and then an accompanying column

@fahadarshad

 

My apologies.

 

I meant drag the Customer ID COlumn and these 2 measures

Regards,
Zubair


Highlighted
Helper I
Helper I

Re: Getting max date and then an accompanying column

Sorry bro; I am very new to Power BI. What does visual drag mean?

Highlighted
Super User III
Super User III

Re: Getting max date and then an accompanying column

HI @fahadarshad

 

See the picture below

 

From the Visualization select table and select the Fields from right most section as shown in the pic

 

10090.png

Regards,
Zubair


Highlighted
Helper I
Helper I

Re: Getting max date and then an accompanying column

Oh ok. 
But I would like to create a table of it rather than visualise it.

Highlighted
Super User III
Super User III

Re: Getting max date and then an accompanying column

@fahadarshad

 

If you are using Excel

 

Put the Customer ID in row field and the 2 MEASURES in VALUE field in the Pivot Table

Regards,
Zubair


Highlighted
Helper I
Helper I

Re: Getting max date and then an accompanying column

@Zubair_Muhammad

 

I am using Power BI desktop.

 

But more importantly, the meausre you have specified for the last product is giving me the wrong priduct. the max date seems to be working though.

 

any reason why the last product is incorrect?

Highlighted
Super User III
Super User III

Re: Getting max date and then an accompanying column

@fahadarshad

 

If you need a Table

 

Go to Modelling Tab>>>NEW TABLE and then use this formula.

 

 

New Table =
SUMMARIZE (
    TableName,
    TableName[Customer ID],
    "Last Date", MAX ( TableName[Date] ),
    "Last Product", CALCULATE (
        FIRSTNONBLANK ( TableName[Product], 1 ),
        FILTER ( TableName, TableName[Date] = MAX ( TableName[Date] ) )
    )
)
Regards,
Zubair


View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Upcoming Events

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors