cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
indhu Member
Member

DAX help - Get latest value for each ID

Hi all, 

 

I have a dataset which looks like below and would like to find the last value in each column for each user. 

 

User Name    |   Value   | Date

---------------------------------------

x                       2          12/01/2018

x                       1          13/01/2018

y                       9          11/01/2018

 

Output like this

 

User Name    |   Value   | Date

---------------------------------------

x                      1            13/01/2018

y                       9          11/01/2018

 

I tried using dax using last nonblank but I am missing something. 

 

latest value = CALCULATE(LASTNONBLANK(table[value,MAX(Table[Date])))

 

Also, tried this 

 

Latest value = CALCULATE(LASTNONBLANK(Table[value],""),FILTER(Table,MAX(Table[Date])))

Can somebody please help? 

 

Thanks,

Indhu

1 ACCEPTED SOLUTION

Accepted Solutions
Super User IV
Super User IV

Re: DAX help - Get latest value for each ID

Hi,

 

This one works

 

=if(HASONEFILTER(Table1[Name]),LOOKUPVALUE(Table1[Value],Table1[Date],[Latest value],Table1[Name],VALUES(Table1[Name])),BLANK())

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

11 REPLIES 11
Super User IV
Super User IV

Re: DAX help - Get latest value for each ID

Hi,

 

These 2 measures work fine

 

Last date = LASTNONBLANK(Data[Date],1)

Value on last date = LOOKUPVALUE(Data[Value],Data[Date],[Last date],Data[User Name],VALUES(Data[User Name]))

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
indhu Member
Member

Re: DAX help - Get latest value for each ID

Thanks @Ashish_Mathur

 

the first measure works as expected. however, when using the second measure I am not able to convert the name to value and don't know how to proceed further. 

 

Value on last date = LOOKUPVALUE(Data[Value],Data[Date],[Last date],Data[User Name],VALUES(Data[User Name]))

 

1. Is it meant to convert name to text? 

2. Did you mean value? even that doesn't work 

 

This part doesn't work Can you please help? 

 

Thanks again,

Indhu

Super User IV
Super User IV

Re: DAX help - Get latest value for each ID

What do you mean by "I am not able to convert the name to value"?  What error does my formula throw up.  The VALUES() function will return a distinct list of Usernames.  SInce in a row, only one name can appear, it will return only a single value.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Jessica_Seiya Established Member
Established Member

Re: DAX help - Get latest value for each ID

For Ashish's second DAX, use SELECTEDVALUE to replace VALUES, this time, it should work.

 

 

Last_Value = LOOKUPVALUE(Data[Value],Data[Date],[Last_Date],Data[User Name],SELECTEDVALUE(Data[User Name]))

2018-10-19_10-33-45.png

 

 

 

 

Highlighted
indhu Member
Member

Re: DAX help - Get latest value for each ID

@Ashish_Mathur Getting a calculation error.

 

A table of multiple values supplied where a single value was expected. 

 Used same measure as provided not sure why it is not working for me 😞  

 

@Jessica_Seiya If I use as suggested by you nothing gets displayed 

 

Thanks,
Indhu

Super User IV
Super User IV

Re: DAX help - Get latest value for each ID

Hi,

 

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
indhu Member
Member

Re: DAX help - Get latest value for each ID

@Ashish_Mathur please find the attachment for the file.

 

test.pbix

 

Thanks,

Indhu.

Super User IV
Super User IV

Re: DAX help - Get latest value for each ID

Hi,

 

This one works

 

=if(HASONEFILTER(Table1[Name]),LOOKUPVALUE(Table1[Value],Table1[Date],[Latest value],Table1[Name],VALUES(Table1[Name])),BLANK())

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

roofi00 Regular Visitor
Regular Visitor

Re: DAX help - Get latest value for each ID

Hey, nice solution.

What about situation where there are mutliple values and we want to have a sum of them by each category and latest date?

 

thanks 🙂

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors