March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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
Solved! Go to Solution.
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"
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:
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
89 | |
84 | |
70 | |
51 |
User | Count |
---|---|
206 | |
143 | |
97 | |
79 | |
68 |