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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
svishwanathan
Helper III
Helper III

Power Query Syntax

Hello

 

I am trying to write some queries in M and have not found much success.

 

I have a column with years ranging from 1985 to 2026. I want to find the min year and also the relative year (which is the year in the row relative to min year which is 1985)

 

When I write LIst.Min({[Calendar.Year]}), I get the correct result 1985 but when I expand my query it returns incorrect value

 

[Calendar.Year]-(List.Min({[Calendar.Year]}), it returns 0 on all rows. I want that if the row has 1987 as year number then teh relative year shoudl be 2.

When I write [Calendar.Year]-1985, I get the correct value 2

 

I want to use List.Min instead of harcoding the min year

 


Swati

1 ACCEPTED SOLUTION

Sure:

 

Minimum Calendar Year.png

Specializing in Power Query Formula Language (M)

View solution in original post

4 REPLIES 4
MarcelBeug
Community Champion
Community Champion

List.Min({[Calendar.Year]}) just returns the minimum Calendar.Year of each rows Calendar.Year, in other words: just the value of each rows Calendar.Year value.

 

Instead, you must use the minimum value of the entire table column.

 

Example query:

 

let
    Source = #table(type table[Calendar.Year = Int64.Type],List.Zip({{1985..2020}})),
    MinYear = List.Min(Source[Calendar.Year]),
    #"Added Custom" = Table.AddColumn(Source, "WrongCode", each [Calendar.Year] - List.Min({[Calendar.Year]})),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "CorrectCode", each [Calendar.Year] - MinYear)
in
    #"Added Custom1"
Specializing in Power Query Formula Language (M)

Thanks Marcel

 

I will try this but I was wondering that instead of getting the Advanced Editor and tweaking hte code, can i write it as custom column

 

when I edit my query..

 

Please let me know if I am not using the correct language and using M incorrectly here

 


Swati

Sure:

 

Minimum Calendar Year.png

Specializing in Power Query Formula Language (M)

Thanks 

 

I wouldnt go very far without help from you and others

 

Btw I saw one of your videos even today on  Youtube


Thanks to you and all others who are so patiently leading us along

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.

Top Solution Authors