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

Keeping the latest instance of a value based on criteria

Hello - I have the following scenario where I want to keep all the approved requisitions and only keep the latest final disposition date for the Closed requisitions. Can you please assist? Thank you!

 

Unique ID            Req ID        Title                      Status         Final Disposition Date     As of Date

ABC12312019      ABC123      Goal Digger         Approved                                           1/31/2019

ABC12322019     ABC123       Goal Digger         Approved                                           2/28/2019

ABC12332019     ABC123       Goal Digger         Closed                    3/25/2019            3/31/2019

ABC12342019     ABC123       Goal Digger         Approved                                            4/30/2019

ABC12352019     ABC123       Goal Digger         Approved                                            5/31/2019

ABC12362019     ABC123       Goal Digger         Approved                                            6/30/2019

ABC12372019     ABC123       Goal Digger         Closed                     7/2/2019             7/31/2019

11 REPLIES 11
smpa01
Super User
Super User

@gvillanueva1009  is it possible for you to provide the desired solution here based on the data you provided

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

Yes - the data would look like this as the end result: The earlier closed instance would be removed. Thanks!

 

Unique ID            Req ID        Title                      Status         Final Disposition Date     As of Date

ABC12312019      ABC123      Goal Digger         Approved                                           1/31/2019

ABC12322019     ABC123       Goal Digger         Approved                                           2/28/2019

ABC12342019     ABC123       Goal Digger         Approved                                            4/30/2019

ABC12352019     ABC123       Goal Digger         Approved                                            5/31/2019

ABC12362019     ABC123       Goal Digger         Approved                                            6/30/2019

ABC12372019     ABC123       Goal Digger         Closed                     7/2/2019             7/31/201

@gvillanueva1009  thanks. Here you go !!!

Power Query _ M_Code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyNjQyNjQyMLRU0oHygAz3/MQcBZfM9PTUIpBwQUFRfllqCpAJRIb6xob6YA2xOmQZYKRvZEGiAc45+cVg7cb6Rqb6ULXGWBxiQopDTPSNDdANMCXFAFMsLjAjxQAzLC4wJzIozPWNYCFhjnBHLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Unique ID" = _t, #"Req ID" = _t, Title = _t, Status = _t, #" Final Disposition Date" = _t, #"As of Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Unique ID", type text}, {"Req ID", type text}, {"Title", type text}, {"Status", type text}, {" Final Disposition Date", type date}, {"As of Date", type date}}),
    #"Filled Down" = Table.FillDown(#"Changed Type",{"Unique ID", "Req ID", "Title"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Status] = "Closed")),
    #"2" = Table.SelectRows(#"Filtered Rows", let latest = List.Max(#"Filtered Rows"[#" Final Disposition Date"]) in each [#" Final Disposition Date"] = latest),
    #"1" = Table.SelectRows(#"Filled Down", each ([Status] = "Approved")),
    Custom1 = #"1"&#"2"
in
    Custom1

Power Query _ M_Result

 

Capture.PNG

DAX_Code

 

Table = 
VAR _1= FILTER(FILTER(Source,Source[Status]="Closed"),Source[ Final Disposition Date]=MAX(Source[ Final Disposition Date]))
VAR _2 =FILTER(Source,Source[Status]="Approved")
VAR _3 = UNION(_2,_1)
RETURN _3

DAX_ResultDAX_Result

 

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

Thank you! I received this error: "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value"

please check

https://drive.google.com/open?id=10bhcD0ybzsffYtoy6VV4iXActhWcpj99

 

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

Thank you! It works in your file but when I try it, it doens't. I am pretty sure I am doing something wrong. Smiley Sad

Thank you! So these options create a table with my desired result?

 

 

yes !!!

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

@gvillanueva1009 ,

Thank you. @ImkeF  is there a way to delete rows based on criteria?


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @gvillanueva1009 , 

Depending on big your dataset is, an easy way is to filter out the row in Power Query. On each refresh it will continue to filter those rows. Not Elegant, but quick!


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @gvillanueva1009 ,

Not sure how to create this, but the logic seems to be delete unless table[ Status] = "Approved", or [Final Disposition Date ]= MAX(table[Final Disposition Date]. Is that correct? In Power Query? @KenPuls ?

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.