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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sahgir123
Frequent Visitor

Want to create flag for max date

I have table like -  input table - want to create new custom column, if Date column contain max date then 1 else 0 using M-Code.

ContentFilesDate
BinaryJan2301/01/2023
BinaryFeb2301/02/2023
BinaryFeb2402/02/2024
BinaryFeb2414/02/2024

i want output in new column contain

FilesO/p
Jan230
Feb230
Feb241

  Feb 24   1

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

Hi @sahgir123 

 

See if this works for you

let
    maxDate = List.Max( List.Distinct( ChType[Date])),
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMSyyqVNJR8krMMzIG0gaG+kBkZADkxOogybulJsHljXDIm4DkjaDyJtjlDU0Q8rEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Content = _t, Files = _t, Date = _t]),
    ChType = Table.TransformColumnTypes( Source, {{"Date", type date}}, "nl-NL"),
    AddIsMax = Table.AddColumn(ChType, "IsMax", each if [Date] = maxDate then 1 else 0)
in
    AddIsMax

 

This gets me the Dates column from the ChType step: ChType[Date]

It's used in the maxDate variable to retrieve the max value and is used to add the IsMax column

 

I hope this is helpful

View solution in original post

1 REPLY 1
m_dekorte
Super User
Super User

Hi @sahgir123 

 

See if this works for you

let
    maxDate = List.Max( List.Distinct( ChType[Date])),
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsrMSyyqVNJR8krMMzIG0gaG+kBkZADkxOogybulJsHljXDIm4DkjaDyJtjlDU0Q8rEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Content = _t, Files = _t, Date = _t]),
    ChType = Table.TransformColumnTypes( Source, {{"Date", type date}}, "nl-NL"),
    AddIsMax = Table.AddColumn(ChType, "IsMax", each if [Date] = maxDate then 1 else 0)
in
    AddIsMax

 

This gets me the Dates column from the ChType step: ChType[Date]

It's used in the maxDate variable to retrieve the max value and is used to add the IsMax column

 

I hope this is helpful

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors