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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Aydeedglz
Helper V
Helper V

IF Condition in Power Query using Custom Column to find MIN and MAX date

Hi 

 

I have two dates in my data (the dates are always changing) so I want to identifiy which is the MIN and which is the MAX in a NEW column 

 

I have 

 

Month

4/1/2023

5/1/2023

 

I want a new column that will say for 4/1/2023 - 1 and for 5/1/2023, like this 

 

Month         Order

4/1/2023      1

5/1/2023      2

 

Using custom column, or a way to add a new column 

Aydeedglz_0-1687986769658.png

 

 

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", type date}}),
    Custom1 = Table.AddRankColumn(#"Changed Type","Order",{"Month", Order.Ascending},[RankKind = RankKind.Competition])
in
    Custom1

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

In this case is working for you because you only have 2 columns but if you have more it will give you the row number where the next value is starting 

 

Aydeedglz_5-1688056069317.png

 

You might as well show a representative sample, explain the business context and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
PhilipTreacy
Super User
Super User

Hi @Aydeedglz 

 

You could use this

= if [Month] = List.Max(#"Changed Type"[Month]) then 2 else 1

 

where this step is referencing the [Month] column in the previous step, which in this case is called #"Changed Type".  In your case it may well be called soemthign else, you'll need to change it accordingly.

 

Regards

 

Phil

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi I still have the problem 

 

Aydeedglz_0-1688052165355.png

Aydeedglz_1-1688052175731.pngAydeedglz_2-1688052189477.png

 

Aydeedglz_4-1688052994944.png

 

Aydeedglz_3-1688052465768.png

 

@Aydeedglz 

 

Download example PBIX file

 

You haven't put the 1 after the else

 

It should be 

 

if [#"Month - Copy"] = List.Max(#"Changed Type"[#"Month - Copy"]) then 2 else 1

 

 

and this only works when the previous step is named #"Changed Type"

 

If you look at my example file (linked above) you'll see this works.

 

FYI - One of the reasons this is taking so long to solve is because you only gave us a snippet of the actual data in your original post and haven't provided any actual data to work with so we are guessing as to what yor data looks like and what steps you have in your query.

 

It's always best to provide a good sample of your data in a file or table - not images.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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