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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
amart
Frequent Visitor

MAX Date for Row in Table but only for certain columns

Hey guys, 

I've been working on this for a while and my gut feeling is that i'm missing something  obvious here. Relatively knew to DAX but have experience in other programming languages.  I'm only working in excel at this point through PowerPivot. 

 

I've got a table with rows of data that that is updated each year. I'm trying to find the last row in each year to display to my user how much time we have until the licnese needs to be renewed. I've gotten close with both the MAX(date) and LASTDATE() function but keep running into an issue. 

 

amart_0-1666874808671.png

 

amart_1-1666874819721.png

I want to display the MAX date in the table only in context for certain columns. The issue is when the contractor changes it interprets it as a new row context and gives a new row in the Pivot Table. So in this case I want to ignore the Contractor context.

 

Below is the ideal result.

amart_2-1666875078717.png

 

Any help would be much appreciated. Also,  the other help i've gotten from reading other posts has been great, so thanks for everyone's help direct or indirect!

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @amart 
Please refer to attached sample file with the solution

1.png2.png

Exp_Date :=
VAR CurrentIDTable =
    CALCULATETABLE (
        Table1,
        ALL ( Table1 ),
        ALL ( Table2 ),
        VALUES ( Table1[Holding_ID] )
    )
VAR LastRecord =
    TOPN ( 1, CurrentIDTable, Table1[Date] )
VAR LastContractor =
    MAXX ( LastRecord, Table1[Contractor] )
VAR CurrentContractor =
    MAX ( Table1[Contractor] )
RETURN
    IF ( CurrentContractor = LastContractor, MAX ( Table1[Date] ) )

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

Hi @amart 
Please refer to attached sample file with the solution

1.png2.png

Exp_Date :=
VAR CurrentIDTable =
    CALCULATETABLE (
        Table1,
        ALL ( Table1 ),
        ALL ( Table2 ),
        VALUES ( Table1[Holding_ID] )
    )
VAR LastRecord =
    TOPN ( 1, CurrentIDTable, Table1[Date] )
VAR LastContractor =
    MAXX ( LastRecord, Table1[Contractor] )
VAR CurrentContractor =
    MAX ( Table1[Contractor] )
RETURN
    IF ( CurrentContractor = LastContractor, MAX ( Table1[Date] ) )
amart
Frequent Visitor

That worked! I have a bunch of other tables i'm going to build using the same format! Thanks so much! This community is awesome!

Anonymous
Not applicable

Hello you could try

if([license type]= Blank(),Blank(),max([date]))

 

Then use filter panel to filter out blank values

Thank you for your response. I had do not repeat on the pivot table settings so it didn't show property. Below is what the actual values are. 

 

amart_0-1666876812304.png

So its pulling in the entire row for the prior year date because the contract has changed. In reality I just want the latest row in the table for only Holding, License Type and Entity.

 

Thanks again for your help. 

Anonymous
Not applicable

oh ok i created a sample of your data:

Screenshot 2022-10-27 171527.png


is this the result you want below?"

Screenshot 2022-10-27 171535.png

 

if yes then this is the formula i used:

Latest Date = CALCULATE(MAX(Amart[Exp. Date]),ALLEXCEPT(Amart,Amart[Contractor]))

Thanks for you help here, it wasnt the solution I was looking for in this example, but I had another issue I was working on where this worked great! Thank you!

amart
Frequent Visitor

This is the full data from the tables. 

 

Table 1

amart_1-1666877015866.png

Table 2

amart_2-1666877027603.png

Thanks again. 

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.