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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
atowriss99
Helper I
Helper I

Creating a custom column in M to get Prev Max Date

I have created a column to get the Max Date form a Date column in my table and now I want to create a new column to get the Previous Max Date.  

I tried this to get the it:
Table.AddColumn(#"Changed Type10", "Prev Max Rate Date", each Date.From(List.Max(#"Changed Type10"[Rate Start Date]))<(#"Changed Type10"[Max Rate Date])) 

and I get this error:
Expression.Error: We cannot apply operator < to types List and Date.
Details:
Operator=<
Left=[List]
Right=3/16/2024

Here's what I used to get Max Date: 
Table.AddColumn(#"Added Custom3", "Max Rate Date", each Date.From(List.Max(#"Added Custom3"[Rate Start Date])))

What steps do I need to take after adding my Max Date column to get Prev Max date?
Thanks

1 ACCEPTED SOLUTION
v-xuxinyi-msft
Community Support
Community Support

Hi @atowriss99 

 

Are you trying to create a custom column to get the second maximum? If so, you can try the following:

 

My sample:

vxuxinyimsft_0-1710922604744.png

 

Max date:

vxuxinyimsft_1-1710922664668.png

 

The second Max date:

 

List.Sort(#"Addcolumn"[Date], Order.Descending){1}

 

 

Result:

vxuxinyimsft_2-1710922842407.png

 

Here is the whole M function in Advanced Editor:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ30TcyMDJRitWJVjLVNwNxjMEcC31DM4SUmb6hEULOFIUHVGmI4JnrG5ogeJYopqCaCTQDYgyQGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Addcolumn" = Table.AddColumn(#"Changed Type", "Max Rate Date", each Date.From(List.Max(#"Changed Type"[Date]))),
    #"Added Custom" = Table.AddColumn(#"Addcolumn", "Previous Max Date", each List.Sort(#"Addcolumn"[Date], Order.Descending){1}, type date)
in
    #"Added Custom"

 

 

If I've misunderstood you, please provide detailed sample data and the results you are hoping for: How to provide sample data in the Power BI Forum - Microsoft Fabric Community . Or show it as a screenshot or pbix. Please remove any sensitive data in advance. If uploading pbix files please do not log into your account.

 

Best Regards,
Yulia Xu

 

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

1 REPLY 1
v-xuxinyi-msft
Community Support
Community Support

Hi @atowriss99 

 

Are you trying to create a custom column to get the second maximum? If so, you can try the following:

 

My sample:

vxuxinyimsft_0-1710922604744.png

 

Max date:

vxuxinyimsft_1-1710922664668.png

 

The second Max date:

 

List.Sort(#"Addcolumn"[Date], Order.Descending){1}

 

 

Result:

vxuxinyimsft_2-1710922842407.png

 

Here is the whole M function in Advanced Editor:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ30TcyMDJRitWJVjLVNwNxjMEcC31DM4SUmb6hEULOFIUHVGmI4JnrG5ogeJYopqCaCTQDYgyQGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Addcolumn" = Table.AddColumn(#"Changed Type", "Max Rate Date", each Date.From(List.Max(#"Changed Type"[Date]))),
    #"Added Custom" = Table.AddColumn(#"Addcolumn", "Previous Max Date", each List.Sort(#"Addcolumn"[Date], Order.Descending){1}, type date)
in
    #"Added Custom"

 

 

If I've misunderstood you, please provide detailed sample data and the results you are hoping for: How to provide sample data in the Power BI Forum - Microsoft Fabric Community . Or show it as a screenshot or pbix. Please remove any sensitive data in advance. If uploading pbix files please do not log into your account.

 

Best Regards,
Yulia Xu

 

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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.