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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
danielgibbs
Frequent Visitor

Trying to use MAX and IF functions (like in Excel) based on another column

Hi Everyone,

 

Trying to use MAX and IF functions(Based in excel) within a table to find a Date value (MAX_DATE) in a custom column. I want Max date based on AssetID to populate in the MaxDate column.

 

Here's an example of the dataset.

 

ASSET_IDEND_DATEMAX_DATE
1006/30/20179/1/2019
1006/30/20179/1/2019
1009/1/20199/1/2019
1006/30/20179/1/2019
1016/30/201711/1/2019
10111/1/201911/1/2019
1016/30/201811/1/2019
1026/30/20173/1/2020
1023/1/20203/1/2020
1026/30/20173/1/2020
1029/1/20193/1/2020
10312/31/201912/31/2021
10312/31/202112/31/2021

 

Thanks in advance for your help!!!

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

If you can use a Measure instead, this should be simply:

 

MAX_DATE = MAX(Assets[END_DATE])

Then just put your ASSET_ID and this measure into a table visualization.

 

Another way to go would be to create an ASSET_IDS table with unique asset ids and a custom column in that table like so:

 

MAX_DATE = MAXX(RELATEDTABLE(Assets),[END_DATE])

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-yuezhe-msft
Employee
Employee

Hi @danielgibbs,

In your scenario, please firstly open Query Editor and add an index column to your current table as shown in the following screenshot.
1.png

Secondly, create a new column using the formula below.

Max Date = CALCULATE(MAX(Table1[END_DATE]),FILTER(Table1,Table1[ASSET_ID]=EARLIEST(Table1[ASSET_ID])))

Thirdly, create a table visual using all the fields. For more details, you can check the example in the attached PBIX file.
2.PNG

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
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

4 REPLIES 4
v-yuezhe-msft
Employee
Employee

Hi @danielgibbs,

In your scenario, please firstly open Query Editor and add an index column to your current table as shown in the following screenshot.
1.png

Secondly, create a new column using the formula below.

Max Date = CALCULATE(MAX(Table1[END_DATE]),FILTER(Table1,Table1[ASSET_ID]=EARLIEST(Table1[ASSET_ID])))

Thirdly, create a table visual using all the fields. For more details, you can check the example in the attached PBIX file.
2.PNG

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

thanks for your help on this!!

Greg_Deckler
Super User
Super User

If you can use a Measure instead, this should be simply:

 

MAX_DATE = MAX(Assets[END_DATE])

Then just put your ASSET_ID and this measure into a table visualization.

 

Another way to go would be to create an ASSET_IDS table with unique asset ids and a custom column in that table like so:

 

MAX_DATE = MAXX(RELATEDTABLE(Assets),[END_DATE])

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

thanks for your help on this one!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.