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
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
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

Top Solution Authors