Forum Discussion
Get a Status from related table given many Filters and most recent date
Hello Everyone!
this is my first time using this forum. Here is what is happening:
1 - I have a table that records all documents sent to me. This table has the Name of Owner, Type Of document, Date of Issue, and Status.
2 - I Have another table with the name of all People registred.
3 - On the table with all registred people i´m trying to add a column with the status of the most recent document that person sent from a certain type.
Exemple:
Person A has sent 5 documents. Which 2 are from type X. From those, one has a date from 2018 and the other from 2019.
I´d like to get status on the most recent Status of documents Type X from person A
Table of Document
Name | Type | Date | Status
A X 12/18 on
A X 12/19 off
A Y 01/17 on
A Y 12/17 neutral
A Z 01/19 off
......
What i want on the registries table:
Name | Status
A off
B on
C off
....
can anyone help me please? I´m sure there must be a simple solution which i can't think of.
ps: Another important thing is that i´m actually doing this on Excel Power Pivot, but given that Dax behaves the same way, i dont this is an issue.
ps2: i also filter out all neutral status but i believe adding another condition would be ease after getting the solution for this problem.
Anonymous - First, welcome. Second, I believe you want Lookup Min/Max. So basically, lookup the max date and then grab the status of that date and return it. https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434
Column = Var __Date = MAXX(RELATEDTABLE('Document'),[Date]) RETURN MAXX(FILTER(RELATEDTABLE('Document'),[Date]=__Date),[Status])Since are new (your post is excellent btw), please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, 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
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
4 Replies
- Greg_Deckler
Community Champion
Anonymous - First, welcome. Second, I believe you want Lookup Min/Max. So basically, lookup the max date and then grab the status of that date and return it. https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434
Column = Var __Date = MAXX(RELATEDTABLE('Document'),[Date]) RETURN MAXX(FILTER(RELATEDTABLE('Document'),[Date]=__Date),[Status])Since are new (your post is excellent btw), please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, 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
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.- AnonymousNot applicable
Greg_Deckler Thank you very much for your tips and answer! It worked! I just had to change the first part to include the filter of document type
Var __Date = MAXX(FILTER(RELATEDTABLE('Document');[Type] = "X"),[Date])- Greg_Deckler
Community Champion
Anonymous - Awesome! Glad you were able to modify the calculation to your needs. It's sooooo hard to come up with DAX that is 100% exactly right without the PBIX or very clear guidance so a lot of the solutions are dependent upon being adapted to specific circumstances!
- Jimmy801
Community Champion
Hello Anonymous
here a solution in Power Query. The first two steps are to create data example, the third step is a Table.AddColumn that filters the Mail-Table, sorts it and choose the first row of the column "Status"
let Mail = let Source = #table ( {"Name","Type","Date","Status"}, { {"A","X","01.01.20","on"}, {"A","X","08.02.20","off"}, {"A","Y","03.05.20","on"}, {"A","Y","01.12.21","neutra"}, {"B","Z","01.01.01","on"}, {"B","X","08.01.20","off"} } ), TransDate = Table.TransformColumns ( Source, { "Date", each Date.From(_,"de-DE"), type date } ) in TransDate, Users= #table ( {"Name"}, { {"A"}, {"B"} } ), AddLatestStatus = Table.AddColumn ( Users, "Most recent status", (add)=> Table.Sort(Table.SelectRows(Mail, each [Name]= add[Name]), {"Date", Order.Descending})[Status]{0} ) in AddLatestStatusCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy