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
itspossible
Frequent Visitor

How to find rows associated with latest date value

Hello! I've tried my hand at a number of solutions offered in the forums for similar topics but haven't succeeded - mostly because I'm extremely new to DAX/Powerquery/M.

 

Basically, I have a table with facebook channel data, where each post on my page has several rows - one row per day the post was active. All I need is a table or way to parse this given table that only selects all unique posts (along with all the other columns associated with them) for the latest date. The latest date is different for each post, of course. Can someone please outline the steps required and the code to use in order to achieve this? I have attached sample table belowpowerbiForum.png

 

Basically, for each unique instance of "message" I only want to retain the latest date in the column "db_date". And to ensure all other columns carry through. Thanks!

 

 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @itspossible

From the screenshot, it seems unique "post id" associated with each unique instance of "message", so i use "post id" as a test.

create a new table from your table

Table = FILTER(ALL(Table1),[date]=CALCULATE(MAX(Table1[date]),ALLEXCEPT(Table1,Table1[post id])))

Original table

7.png

New created table

8.png

 

Best Regards

Maggie

View solution in original post

8 REPLIES 8
v-juanli-msft
Community Support
Community Support

Hi @itspossible

From the screenshot, it seems unique "post id" associated with each unique instance of "message", so i use "post id" as a test.

create a new table from your table

Table = FILTER(ALL(Table1),[date]=CALCULATE(MAX(Table1[date]),ALLEXCEPT(Table1,Table1[post id])))

Original table

7.png

New created table

8.png

 

Best Regards

Maggie

You can create a new table with the SUMMARIZE function. You get a table with unique posts with a MAX date. So you will have the maximum DB_DATE per post. 

 

Create a new table under the tab modeling and enter the following code:

 

POST_WITH_MAX_DATE = SUMMARIZE(Sheet1; Sheet1[type]; Sheet1[post_id]; "Total Value"; max(Sheet1[db_date])) 

Hi there, while the code provided works perfectly for those 3 columns referenced in it, it fails its intended purpose when I add the other columns into the query - particularly shares_count, comments_count, likes_count and reactions_total_count. I am back to seeing multiple entries for post_id. How can I fix this?

So close to a solution. Anyone have any suggestions?

bump

@itspossible

 

Your dropbox link doesn't work

 

Nevertheless, please see if this blog post is useful

 

http://www.excelnaccess.com/grouping-summarizing-dax-vs-power-query-m/


Regards
Zubair

Please try my custom visuals
Greg_Deckler
Super User
Super User

Can you post example data that can be copied and pasted? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you. File is attached in dropbox link.

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.