cancel
Showing results 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.

Anonymous
Not applicable

## Comapre 3 rows if dates and Display the latest date row

HI

I have a table with 3 coulms having Approval date , Submitted date, Planned Date. i need to display only the row with the max date of these three date columns per each country blow is sample of my data

 Reg Num Country Approval Date Sub date Planned date 123 India Dec 10 2022 123 India Aug 10 2022 123 India Jun 10 2022 345 US Sep 20 2022 345 US Aug 20 2022 145 France Jun 20 2022

Output should be

 Reg Num Country Approval date Submitted date Planned date 123 India Dec 10 2022 345 US Sep 20 2022 145 France Jun 20 2022
1 ACCEPTED SOLUTION
Community Champion

Hi @Anonymous ,

You could create a column as below:-

``````Final Date =
VAR app_date =
CALCULATE (
MAX ( 'Table'[Approval Date] ),
FILTER ( 'Table', 'Table'[Reg Num] = EARLIER ( 'Table'[Reg Num] ) )
)
VAR sub_date =
CALCULATE (
MAX ( 'Table'[Sub date] ),
FILTER ( 'Table', 'Table'[Reg Num] = EARLIER ( 'Table'[Reg Num] ) )
)
VAR plan_date =
CALCULATE (
MAX ( 'Table'[Planned date] ),
FILTER ( 'Table', 'Table'[Reg Num] = EARLIER ( 'Table'[Reg Num] ) )
)
RETURN
MAX ( MAX ( app_date, sub_date ), plan_date )``````

Then create these measure for your date as below:-

``````approval_date =
IF (
MAX ( 'Table'[Approval Date] ) = MAX ( 'Table'[Final Date] ),
MAX ( 'Table'[Approval Date] ),
BLANK ()
)``````
``````planned_date =
IF (
MAX ( 'Table'[planned Date] ) = MAX ( 'Table'[Final Date] ),
MAX ( 'Table'[planned Date] ),
BLANK ()
)``````
``````sub_date =
IF (
MAX ( 'Table'[sub Date] ) = MAX ( 'Table'[Final Date] ),
MAX ( 'Table'[sub Date] ),
BLANK ()
)``````

Output:-

Refer a file below:-

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

3 REPLIES 3
Super User

``````Approval_Date =
IF (
CALCULATE (
MAX ( 'tbl'[Approval Date] ),
ALLEXCEPT ( tbl, tbl[Approval Date] )
)
= MAX ( 'tbl'[Approval Date] ),
MAX ( 'tbl'[Approval Date] )
)
----
Planned_date =
IF (
CALCULATE ( MAX ( tbl[Planned date] ), ALLEXCEPT ( tbl, tbl[Planned date] ) )
= MAX ( tbl[Planned date] ),
MAX ( tbl[Planned date] )
)
---
Sub_date =
IF (
CALCULATE ( MAX ( 'tbl'[Sub date] ), ALLEXCEPT ( tbl, 'tbl'[Sub date] ) )
= MAX ( 'tbl'[Sub date] ),
MAX ( 'tbl'[Sub date] )
)``````

file hir:
https://dropmefiles.com/nsDa5

Super User

HI @Anonymous ,

You can get this by just measure creation avoiding any column creation.

Create 3 measures as follows:

``````# Approval Date Max = // getting logic for approval date comparison at a country level
VAR ApprovalDate_max = // getting maximum approval date at a country level
CALCULATE(MAX(PBIQueryData[Approval Date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR SubDate_max = // getting maximum substitute date at a country level
CALCULATE(MAX(PBIQueryData[Sub date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR PlannedDate_max = // getting maximum planned date at a country level
CALCULATE(MAX(PBIQueryData[Planned date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR date_comparison = // comparing all three dates to get the maximum value
IF(
ApprovalDate_max > SubDate_max && ApprovalDate_max > PlannedDate_max,
ApprovalDate_max,
BLANK()
)

RETURN
date_comparison``````
``````# Substitue Date Max = // getting logic for substitute date comparison at a country level
VAR ApprovalDate_max = // getting maximum approval date at a country level
CALCULATE(MAX(PBIQueryData[Approval Date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR SubDate_max = // getting maximum substitute date at a country level
CALCULATE(MAX(PBIQueryData[Sub date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR PlannedDate_max = // getting maximum planned date at a country level
CALCULATE(MAX(PBIQueryData[Planned date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR date_comparison = // comparing all three dates to get the maximum value
IF(
SubDate_max > ApprovalDate_max && SubDate_max > PlannedDate_max,
SubDate_max,
BLANK()
)

RETURN
date_comparison``````
``````# Planned Date Max = // getting logic for planned date comparison at a country level
VAR ApprovalDate_max = // getting maximum approval date at a country level
CALCULATE(MAX(PBIQueryData[Approval Date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR SubDate_max = // getting maximum substitute date at a country level
CALCULATE(MAX(PBIQueryData[Sub date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR PlannedDate_max = // getting maximum planned date at a country level
CALCULATE(MAX(PBIQueryData[Planned date]), FILTER(ALL(PBIQueryData), PBIQueryData[Country] = MAX(PBIQueryData[Country])))

VAR date_comparison = // comparing all three dates to get the maximum value
IF(
PlannedDate_max > ApprovalDate_max && PlannedDate_max > SubDate_max,
PlannedDate_max,
BLANK()
)

RETURN
date_comparison``````

Move them to the table visual and you get the required result:

Make sure to modify the names of these measures as per your requirement and also the format of the date for them.

Hope this helps.

Best Regards,

Pragati Jain

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Proud to be a Super User!!

Community Champion

Hi @Anonymous ,

You could create a column as below:-

``````Final Date =
VAR app_date =
CALCULATE (
MAX ( 'Table'[Approval Date] ),
FILTER ( 'Table', 'Table'[Reg Num] = EARLIER ( 'Table'[Reg Num] ) )
)
VAR sub_date =
CALCULATE (
MAX ( 'Table'[Sub date] ),
FILTER ( 'Table', 'Table'[Reg Num] = EARLIER ( 'Table'[Reg Num] ) )
)
VAR plan_date =
CALCULATE (
MAX ( 'Table'[Planned date] ),
FILTER ( 'Table', 'Table'[Reg Num] = EARLIER ( 'Table'[Reg Num] ) )
)
RETURN
MAX ( MAX ( app_date, sub_date ), plan_date )``````

Then create these measure for your date as below:-

``````approval_date =
IF (
MAX ( 'Table'[Approval Date] ) = MAX ( 'Table'[Final Date] ),
MAX ( 'Table'[Approval Date] ),
BLANK ()
)``````
``````planned_date =
IF (
MAX ( 'Table'[planned Date] ) = MAX ( 'Table'[Final Date] ),
MAX ( 'Table'[planned Date] ),
BLANK ()
)``````
``````sub_date =
IF (
MAX ( 'Table'[sub Date] ) = MAX ( 'Table'[Final Date] ),
MAX ( 'Table'[sub Date] ),
BLANK ()
)``````

Output:-

Refer a file below:-

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Announcements

#### 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

#### Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors