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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
paulomoreira
Regular Visitor

Calculate the name column with most recent date

Hi have 2 columns, how can i know the name of column and date for most recent date for the product.

Exemple: product 1 is column B with 20-07-2020

product 2 is column A with 3-2-2019

 

ProductAB
110-07-202020-07-2020
23-2-201901-12-2018
1 ACCEPTED SOLUTION

@paulomoreira 

Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00DUw1zUyMDIAcowQnFidaCUjoJCxrhFQwNASyDQw1DUEcyyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, A = _t, B = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type date}, {"B", type date}},"en-gb"),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Recent Date", each List.Max({[A],[B]})),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Recent Date", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Column Name", each let 
  i = {[A],[B]} 
in
  Table.ColumnNames(#"Changed Type")
  { List.PositionOf(i,[Recent Date]) + 1})
in
    #"Added Custom1"

 

Fowmy_0-1610883425254.png

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@paulomoreira 

DAX doesn't support retrieving the column name or any meta data, you can do it in Power Query if you like.

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

How can i do with M?

@paulomoreira 

Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00DUw1zUyMDIAcowQnFidaCUjoJCxrhFQwNASyDQw1DUEcyyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, A = _t, B = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type date}, {"B", type date}},"en-gb"),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Recent Date", each List.Max({[A],[B]})),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Recent Date", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Column Name", each let 
  i = {[A],[B]} 
in
  Table.ColumnNames(#"Changed Type")
  { List.PositionOf(i,[Recent Date]) + 1})
in
    #"Added Custom1"

 

Fowmy_0-1610883425254.png

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.