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
Mat42
Helper III
Helper III

Latest Date Financial Year

This feels both simple and probably not possible all at the same time.

 

So, this is basically my dataset:

Mat42_0-1731059504406.png

I used the following M to create the Latest column, which displays a 1 if the date is the latest for each Code:

 

if [Date] = List.Max(let currentCode = [Code]
in Table.SelectRows(#"Renamed Columns",
each [Code] = currentCode)[Date])
then 1
else 0

 

And it works. But now they've decided they want a 1 alongside every date that is the latest date for each financial year, so the dataset would look like this:

Mat42_0-1731068428665.png

 

To demonstrate: for code 11111 there is a 1 alongside 02/03/2024 because it is the latest date in financial year 2023-2024 and alongside 01/05/2024 because it is the latest date in financial year 2024-2025. Both entries for 33333 have a 1 because each entry is the latest (and only) date in separate financial years.

 

They want this done in Power Query for reasons they haven't yet told me.

 

Is this possible? I don't mind adding in new columns or merging tables if I need to.

1 ACCEPTED SOLUTION

Hi @Angith_Nair ,
According to your question, we have tried other methods, based on your actual data, I hope to help you with your question!
Our first step is to find the maximum date under each fiscal year, which we call MAXTable.

vxingshenmsft_0-1731378657359.png

Then we merger with the original table to get a MaxDate, which is the maximum date value for each fiscal year.

vxingshenmsft_1-1731378711187.png

 


And finally, we add a new column to find out if each ID is the latest date.

vxingshenmsft_2-1731378731641.png

I hope this helps you solve your problem, if you have further questions you can check out the uploaded pbix, I'd be incredibly proud to solve your query!

Hope it helps!

Best regards,
Community Support Team_ Tom Shen

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

6 REPLIES 6
FreemanZ
Super User
Super User

hi @Mat42 ,

 

try like:

if 

[Date] = 

List.Max(

    let currentCode = [Code], currentyear = [FinYear]

    in Table.SelectRows(

       #"Renamed Columns",

        each [Code] = currentCode and each [FinYear] = currentyear )[Date]

)

then 1

else 0

Thanks for replying.

 

The code is getting flagged at this point:

 

Mat42_0-1731078511332.png

Token Literal expected

Angith_Nair
Continued Contributor
Continued Contributor

Hi @Mat42 

 

Create a financial year column that identifies the financial year for each Date.

AddFinancialYear = Table.AddColumn(#"Renamed Columns", "FinancialYear", each if Date.Month([Date]) >= 4 then Date.Year([Date]) + 1 else Date.Year([Date]), Int64.Type)

Modify the logic as per the financial year:

AddLatestFlag = Table.AddColumn(AddFinancialYear, "Latest", each 
    if [Date] = List.Max(
        Table.SelectRows(AddFinancialYear, each [Code] = [Code] and [FinancialYear] = [FinancialYear])[Date]
    ) then 1
    else 0)

Hi, thanks.

 

I tried this and I've ended up like this (this is the actual data):

 

Mat42_1-1731080477587.png

I'd expect a 1 to be alongside 10000215136 and 1000025230 because they are the latest date for each financial year because they are the only entries, and for 1000025429 there should be a 1 against 21/002/2024 because that is the latest date in financial year 2023/2024 and a 1 against 19/06/2024 because it is the latest date in 2024/2025.

Hi @Angith_Nair ,
According to your question, we have tried other methods, based on your actual data, I hope to help you with your question!
Our first step is to find the maximum date under each fiscal year, which we call MAXTable.

vxingshenmsft_0-1731378657359.png

Then we merger with the original table to get a MaxDate, which is the maximum date value for each fiscal year.

vxingshenmsft_1-1731378711187.png

 


And finally, we add a new column to find out if each ID is the latest date.

vxingshenmsft_2-1731378731641.png

I hope this helps you solve your problem, if you have further questions you can check out the uploaded pbix, I'd be incredibly proud to solve your query!

Hope it helps!

Best regards,
Community Support Team_ Tom Shen

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

 

You are awesome!

 

Although this didn't quite do what I needed because it gave me the latest date rather than the latest financial date, I actually removed a financial year column from the dataset, so I used that instead of 'Year' for the grouping and it worked great. 

 

Thanks!

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!

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.