Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Shelley
Post Prodigy
Post Prodigy

How to calculate last date by transaction groups?

I have a transaction table of procedure audits. The same procedure may have been audited multiple times, and I want to find the latest date a particular procedure was audited and who conducted the audit. How do I do this?

 

The fields are all in the same table: Audit end Date, Procedure ID and Audited By ID.

 

Procedure ID   Audit End Date                 Audited By ID

abc                      8/11/17   1:00 pm             Sam

abc                      9/17/17  7:00am               Fred

abc                      9/17/17  10:00 am             Sally

def                      7/1/17   9:30 am              Sally

def                      8/15/17   11:00 am             Greg

 

So, I want results to show:

abc, 9/17/17 by Sally

def, 8/15/17 by Greg

 

and so on.

 

Help is greatly appreciated. Thanks!

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

I would create a new calculated column in your table that flags the latest date. This new column then can be used as filter or even used on a slicer, this DAX statement for the new calculated column would look like this:

 

Is latest audit = 
IF('yourtablename'[Audit End Date] = 
CALCULATE(
MAX('yourtablename'[Audit End Date])
,ALLEXCEPT('yourtablename', 'yourtablename'[Procedure ID])
)
,"True"
,"False"
)

Hope this is what you are looking for

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

3 REPLIES 3
TomMartens
Super User
Super User

Hey,

 

I would create a new calculated column in your table that flags the latest date. This new column then can be used as filter or even used on a slicer, this DAX statement for the new calculated column would look like this:

 

Is latest audit = 
IF('yourtablename'[Audit End Date] = 
CALCULATE(
MAX('yourtablename'[Audit End Date])
,ALLEXCEPT('yourtablename', 'yourtablename'[Procedure ID])
)
,"True"
,"False"
)

Hope this is what you are looking for

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thanks, Tom!

If the aggregation is part of your data shaping process (i.e. if you only need the latest audits in your data model), then Power Query would be an appropriate way to go:

 

let
    Source = Audits,
    #"Grouped Rows" = Table.Group(Source, {"Procedure ID"}, {{"Last Audit", each Table.Max(_,each [Audit End Date]), type record}}),
    #"Expanded Last Audit" = Table.ExpandRecordColumn(#"Grouped Rows", "Last Audit", {"Audit End Date", "Audited By ID"}, {"Audit End Date", "Audited By ID"}),
    #"Restored Column Types" = Value.ReplaceType(#"Expanded Last Audit",Value.Type(Source))
in
    #"Restored Column Types"
Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors