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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Calculating Min date and Max date from multiple date columns for each row in Power query.

Finding Min(Start) date and Max(End) for below sample data- For each Row. Some of the dates will be blank as well

 

NPI ProgramP/n count estMfg Facility LocationLaunchGW1 GW2GW3PD1 Mat'l Received Due DatePD1 BuildStart (MIN)Date End (Max) date)
ABC12XYZ1/1/20212/1/2021 6/1/20213/1/20214/1/2021???????
1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Try these calculations in new custom columns:

 

// Start Date
List.Min({[Launch], [GW1], [GW2], [GW3]... })

// End Date
List.Max({[Launch], [GW1], [GW2], [GW3]... })

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

8 REPLIES 8
Syndicate_Admin
Administrator
Administrator

I have tried your formula but it's not working for me. I am using this formula in Custom column power Query. I am Supposed to get the date 12/31/2025 but I am getting null. All my date columns are Date type.

IDDate1Date2Date3Date4Date5
A1/1/1999nullnull3/4/202512/31/2025

if [Date1] = "1/1/1999"
and [Date2] = null
and [Date3] = null
then List.Max({[Date4], [Date5]})
else null)

 

 

Hi,

 

I think you need to specify the initial date type correctly, like this:

if [Date1] = #date(1999, 01, 01)
    and [Date2] = null
    and [Date3] = null
then List.Max({[Date4], [Date5]})
else null

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




CNENFRNL
Community Champion
Community Champion

Screenshot 2021-11-17 153122.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Hi @CNENFRNL ,

 

I like this solution, much tidier than mine, but I can't seem to work out how this only picks out the dates for evaluation nad no other values/numbers.

In OP's example data, there is a field that just contains the number 12. How is that not lower than the integers behind the date fields?

Hope this makes sense.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




CNENFRNL
Community Champion
Community Champion

Hello, my friend, for a formula

List.Min({"ABC", 10, #date(2021,11,18), null})

I'm sure that string and null value are to be skipped; but frankly speaking, I didn't know why the result is #date, rather than 10.

 

I turned one of my friends for help in the hope of some clue.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

BA_Pete
Super User
Super User

Hi @Anonymous ,

 

Try these calculations in new custom columns:

 

// Start Date
List.Min({[Launch], [GW1], [GW2], [GW3]... })

// End Date
List.Max({[Launch], [GW1], [GW2], [GW3]... })

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi @BA_Pete 

Thanks for the solution, I also kudoed your post and I tired the mquery and its working good, but since we have data as direct query from sql, so we cannot use calculated column function in direct query, can you suggest some dax also to get the same solution by using measure or dax.
Thanks,

Hi @Shivam_Kathpal ,

 

I'd recommend opening a new topic on the Desktop forum.

Direct Query can be a bit tricky for writing some more advanced measures, and DAX isn't really my strong point to be honest.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors