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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mclarin
Regular Visitor

Find earliest date across multiple columns

Any ideas for code to return the earliest date across multiple columns? My table has at least five date columns, I need to return the earliest date per row.

1 ACCEPTED SOLUTION
Nathaniel_C
Super User
Super User

Hi @mclarin ,  I am assuming this is a calculated column. Let me know if this works, as I did it free hand.
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

Calculated column =
VAR _earlycol1 = table[col1]
VAR _earlycol2 = table[col2]
VAR _earlycol3 = table[col3]
VAR _earlycol4 = table[col4]
VAR _calc1 =
    IF ( _earlycol1 < _earlycol2, _earlycol1, _earlycol2 )
VAR _calc2 =
    IF ( calc1 < _earlycol3, _calc1, earlycol3 )
VAR _calc3 =
    IF ( _calc2 < _earlycol4, _calc2, _earlycol4 )
RETURN
    _calc3







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

Proud to be a Super User!




View solution in original post

10 REPLIES 10
Nathaniel_C
Super User
Super User

Hi @mclarin ,  I am assuming this is a calculated column. Let me know if this works, as I did it free hand.
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

Calculated column =
VAR _earlycol1 = table[col1]
VAR _earlycol2 = table[col2]
VAR _earlycol3 = table[col3]
VAR _earlycol4 = table[col4]
VAR _calc1 =
    IF ( _earlycol1 < _earlycol2, _earlycol1, _earlycol2 )
VAR _calc2 =
    IF ( calc1 < _earlycol3, _calc1, earlycol3 )
VAR _calc3 =
    IF ( _calc2 < _earlycol4, _calc2, _earlycol4 )
RETURN
    _calc3







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

Proud to be a Super User!




Anonymous
Not applicable

You Can Also Try This One :

Earliest date =
VAR D1 = min(table[Date1])
VAR D2= min(table[Date2])
VAR D3= min(table[Date3])
VAR D4= min(table[Date4])
return
min(D1,D2,D3,D4)

Hello, thank you for your solution! May I ask if you have a solution for another column that shows the corresponding earliest dates column header please? 

Hi @alya1 ,

This question focused on each row. You asked for earliest date column header. What are looking for? It is also helpful if can either include your data, or a picture of your issue.

 

Thank you,

 

Nathaniel





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

Proud to be a Super User!




Hi Nathaniel_C, thank you for your response! I found what I was looking for here: https://community.fabric.microsoft.com/t5/Desktop/Return-column-name-if-data-matches-another-column-... 

Thank you @Nathaniel_C . This worked great. Since most of the columns were blank, I also performed a check for that, but otherwise, this solved it.

@mclarin can you show your formula including the blank check?

I hope this helps.

 

EarliestDate = 
VAR _earlyBlue = IF(ISBLANK([Blue Print Meeting].[Date]),DATE(2200,1,1),[Blue Print Meeting].[Date])
VAR _earlyIEP = IF(ISBLANK([Initial EP].[Date]),DATE(2200,1,1),[Initial EP].[Date])
VAR _earlyComp = IF(ISBLANK([Composition Meeting].[Date]),DATE(2200,1,1),[Composition Meeting].[Date])
VAR _earlyFund = IF(ISBLANK([Funding Meeting].[Date]),DATE(2200,1,1),[Funding Meeting].[Date])
VAR _earlyTR = IF(ISBLANK([TR Meeting].[Date]),DATE(2200,1,1),[TR Meeting].[Date])
VAR _earlyMedicade = IF(ISBLANK([MA Engagement].[Date]),DATE(2200,1,1),[MA Engagement].[Date])
VAR _earlyPB = IF(ISBLANK([PB 1st Meeting].[Date]),DATE(2200,1,1),[PB 1st Meeting].[Date])
VAR _earlySV = IF(ISBLANK([SV 1st Meeting].[Date]),DATE(2200,1,1),[SV 1st Meeting].[Date])
VAR _calc1 =
    IF(_earlyBlue < _earlyIEP,_earlyBlue,_earlyIEP)
VAR _calc2 =
    IF(_calc1 < _earlyComp,_calc1,_earlyComp)
VAR _calc3 =
    IF(_calc2 < _earlyFund,_calc2,_earlyFund)
VAR _calc4 = 
    IF(_calc3 < _earlyTR,_calc3,_earlyTR)
VAR _calc5 =
    IF(_calc4 < _earlyMedicade,_calc4,_earlyMedicade)
VAR _calc6 =
    IF(_calc5 < _earlyPB,_calc5,_earlyPB)
VAR _calc7 =
    IF(_calc6 < _earlySV,_calc6,_earlySV)
RETURN
    _calc7

@mclarin ,
You are welcome! Glad it worked!
Nathaniel





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

Proud to be a Super User!




Anonymous
Not applicable

hi @Nathaniel_C 

 

how would this change if it is a measure rather than a calculated column?

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 MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.