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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Find Min date by Year (Power Query/M)

I have a calendar table with a date column. I also have another column that represents something like a fiscal year and that column just has the year for each date in it. So if the fiscal year started 1st of August every year, then the fiscal year that started 8/1/2021 would just have "2021" in it from 8/1/2021 until 7/31/2022.

For a different formula, I need to figure out the min date of that fiscal year column for each year dynamically so I can establish a "start date" for a YTD formula.

So in the example above, if Im using todays date of 4/28/2022, the associated fiscal year column would read 2021 and the min date for that would be 8/1/2021. How can I get to that? Or can someone explain how to filter/sort that Date field by Fiscal Year field - that would be awesome! I feel like this should be really easy and I can get the min date in the date column with List.Min but I cannot figure out how to sort/filter by that other column.

If this makes it easier, convert this Dax Column to Power Query:

CALCULATE(MIN('Calendar'[Date]),ALLEXCEPT('Calendar','Calendar'[SchoolYearStart]))

Reason for converting is I want to use this to help create custom YTD flag columns in my Calendar table for PYTD/YTD measures that start with the Fiscal year instead of calendar year.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

So simply, the logic would be  if Month>=8  then the fiscal year is current year, otherwise previous year, then the fiscal date is always xxxx-August-01, right?

 

Please try the following to add custom columns:

if Date.Month([Dates])>=8 then Date.Year([Dates]) else Date.Year([Dates])-1
Date.From( Number.ToText( [Fiscal Year])&"-08-01")

 

Below is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ31zdUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartDate = _t]),
    #"Added Custom" = Table.AddColumn(Source, "EndDate", each Date.From(DateTime.LocalNow())),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"StartDate", type date}, {"EndDate", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Dates", each {Number.From([StartDate])..Number.From([EndDate])}),
    #"Expanded Dates" = Table.ExpandListColumn(#"Added Custom1", "Dates"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Dates",{{"Dates", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"StartDate", "EndDate"}),
    #"Added Custom2" = Table.AddColumn(#"Removed Columns", "Fiscal Year", each if Date.Month([Dates])>=8 then Date.Year([Dates]) else Date.Year([Dates])-1),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Min Fiscal Date", each Date.From( Number.ToText( [Fiscal Year])&"-08-01"))
in
    #"Added Custom3"

 

Eyelyn9_0-1651568031412.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

 

So simply, the logic would be  if Month>=8  then the fiscal year is current year, otherwise previous year, then the fiscal date is always xxxx-August-01, right?

 

Please try the following to add custom columns:

if Date.Month([Dates])>=8 then Date.Year([Dates]) else Date.Year([Dates])-1
Date.From( Number.ToText( [Fiscal Year])&"-08-01")

 

Below is the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ31zdUio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartDate = _t]),
    #"Added Custom" = Table.AddColumn(Source, "EndDate", each Date.From(DateTime.LocalNow())),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"StartDate", type date}, {"EndDate", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Dates", each {Number.From([StartDate])..Number.From([EndDate])}),
    #"Expanded Dates" = Table.ExpandListColumn(#"Added Custom1", "Dates"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Dates",{{"Dates", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"StartDate", "EndDate"}),
    #"Added Custom2" = Table.AddColumn(#"Removed Columns", "Fiscal Year", each if Date.Month([Dates])>=8 then Date.Year([Dates]) else Date.Year([Dates])-1),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Min Fiscal Date", each Date.From( Number.ToText( [Fiscal Year])&"-08-01"))
in
    #"Added Custom3"

 

Eyelyn9_0-1651568031412.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Can you provide some data for this problme to be worked upon?

Refer to this - How to provide sample data in the Power BI Forum - https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Ideal will be to upload the file without confidential/sensitive data to a cloud storage service such as Onedrive/Google Drive/Dropbox/Box (Onedrive preferred) and share the link here.

Helpful resources

Announcements
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.