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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MIkkelHyldig
Helper II
Helper II

Add custom column with max date per item in Power Query

Hi,

I have the following table 1 where and I need to add a custom column with the latest date per Item No.

Table 1 is related to table 2 with Item No and Variant and a date column. When I filter on date column in table 2 on "before 1-2-2021" it should filter out both Item 5001 and not just Variant 5001-002.   

Table 1: Last Purchase date

Item NoVariantLast Purchase DateNEW COLUMN
50015001-00124-01-202025-02-2021
50015001-00225-02-202125-02-2021
50025002-00101-04-202001-04-2020


I have already made a calculated column in Power BI for table 1 but it only filters out 5001-002 and not both as I want. 

Thanks, Mikkel

1 ACCEPTED SOLUTION

Hi, @MIkkelHyldig 

 

If you want to generate the maximum date column with power query, you can try the following method.

Step 1:

vzhangti_1-1646991315106.png

Step 2:

vzhangti_2-1646991336374.png

vzhangti_3-1646991367926.png

Step 3:

The date column of Table 2 establishes a relationship with the MAX column.

vzhangti_4-1646991671892.png

Step 4:

vzhangti_7-1646991911046.pngvzhangti_8-1646991938838.png

Is this the result you were expecting?

 

Best Regards,

Community Support Team _Charlotte

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

6 REPLIES 6
jaideepnema
Solution Sage
Solution Sage

Hi @MIkkelHyldig ,

Is there a relationship between these two tables: 1 and 2 ?

If yes and its basis the date then it will filter out only one row for 5001 with date as 24 January 2020. 

 

Hi @jaideepnema 

Yes its a 1-2. The datamodel im still working on. 
But the custom column is my real issue here. 

If you are trying to filter basis the second table and on the date column it will filter basis the relationship you have created. So can you please give us more details regarding the issue you are facing so its easier for us to understand ?

Sure, @jaideepnema 

What im trying to do is create a custom column (NEW COLUMN) in power query returning the max date based on Item No: 


Table:

Item NoVariantLast Purchase DateNEW COLUMN
50015001-00124-01-202025-02-2021
50015001-00225-02-202125-02-2021
50025002-00101-04-202001-04-2020

Hi, @MIkkelHyldig 

 

If you want to generate the maximum date column with power query, you can try the following method.

Step 1:

vzhangti_1-1646991315106.png

Step 2:

vzhangti_2-1646991336374.png

vzhangti_3-1646991367926.png

Step 3:

The date column of Table 2 establishes a relationship with the MAX column.

vzhangti_4-1646991671892.png

Step 4:

vzhangti_7-1646991911046.pngvzhangti_8-1646991938838.png

Is this the result you were expecting?

 

Best Regards,

Community Support Team _Charlotte

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

Sorry for the late reply! It worked, and even better than my own M-query; 
= Table.AddColumn(#"Filtered Rows", "maxInt", each [
filter = [Item No_],
max=Table.Group(
#"Filtered Rows", {"Item No_"},
{{"MaxFiltered", each List.Max([Last Purchase Date])}}
){[Item No_=filter]}[MaxFiltered]
][max])

Many thanks,
Mikkel

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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