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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Max and Min date

Hi,

 

I am trying to create identify with 1 and 2 the Max and Min date (1=Min and 2=Max).

 

Table2:

Month          Order

April 2023        1

May 2023         2

 

Preferly in Power Query 

10 REPLIES 10
Ahmedx
Super User
Super User

or try this

let 
     YearNow =  Date.Year( DateTime.LocalNow()),
    MonthNow =  Date.Month( DateTime.LocalNow()),
    date1 =#date(YearNow,MonthNow-2,1) ,
    date2 =#date(YearNow,MonthNow-1,1) ,
    date3=  #date(YearNow,MonthNow,1)  ,
    Source = #table(type table [Month=date, Order=Int64.Type], 
                          {
                              {date1,1},{date2,2},{date3,3}
                               })
in
    Source
Ashish_Mathur
Super User
Super User

Hi,

What if there are 12 rows (one for each month)?  What should the result be?


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

in that case you can do this:

Screen Capture #1320.png

 

let
    Source = List.Generate( ()=> #date(2023,1,1),
(x) => x<= #date(2023,12,1),
(x)=> Date.AddMonths(x,1)

),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Month"}, null, ExtraValues.Error),
    #"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Order", 1, 1, Int64.Type)
in
    #"Added Index"

 

 

Ahmedx
Super User
Super User

pls try this

let
    Source = #table(type table [Month=date, Order=Int64.Type], {{#date(2023,4,1),1},{#date(2023,5,1),2}})
in
    Source

Screen Capture #1319.png

Anonymous
Not applicable

In this case month will be dynamic it won't always be those months 

what do you mean dynamic? current month and previous month?

let 
     YearNow =  Date.Year( DateTime.LocalNow()),
      MonthNow =  Date.Month( DateTime.LocalNow()),
    startdate =#date(YearNow,MonthNow-1,1) ,
    EndDate =  #date(YearNow,MonthNow,1)  ,
    Source = #table(type table [Month=date, Order=Int64.Type], 
                          {
                              {startdate,1},{EndDate,2}})
in
    Source
Anonymous
Not applicable

This month JUNE 2023 it has APRIL 2023 and MAY 2023, next month

JULY 2023 it will have MAY 2023 and JUNE 2023, next month

AUGUST 2923 it will have JUNE 2023 and JULY 2023... 

 

It will be always changing 

pls try this

let 
     DateNow =  List.Transform( List.Generate(()=>  Date.AddMonths( Date.From( DateTime.LocalNow()),-2),
        (x) => x <= Date.From( DateTime.LocalNow()),
        (x) =>  Date.AddMonths(x,1)), (x) => Date.StartOfMonth(x)),
    #"Converted to Table" = Table.FromList(DateNow, Splitter.SplitByNothing(), {"Month"}, null, ExtraValues.Error),
    #"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Order", 1, 1, Int64.Type)
in
    #"Added Index"
Anonymous
Not applicable

It didn't worked I added it in the advanced editor, maybe by doing step by step?

Sample PBIX file attached

Max and Min date.pbix

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.