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
Elisa_E
Helper I
Helper I

LASTNONBLANK and MAX

Hello,

 

I have a very large dataset with multiple entries per account per year. I need to pull a text variable (contractor) into a new table based on the last year in the dataset. The issue is that I have multiple entries for the same year for the same account. The variable I need to pull (contractor) is always consistent for a given year. I first tried using LASTNONBLANK , but the data set is not sorted by year, so I do not always have the correct result. Is there a way I can combine a formula with MAX on the year to filter and LASTNONBLANK?

 

Thank you in advance.

LPBI.png

 

1 ACCEPTED SOLUTION

@Elisa_E

 

May be a MEASURE like this

 

LastContractor =
CALCULATE (
    MAX ( Table1[Contractor] ),
    FILTER ( Table1, Table1[Year] = MAX ( Table1[Year] ) )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

 

For a smaller dataset, could you show the input Tables and desired output.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

InputInputOutputOutput

Hi,

 

Share the link from where i can download your Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Elisa_E

 

May be a MEASURE like this

 

LastContractor =
CALCULATE (
    MAX ( Table1[Contractor] ),
    FILTER ( Table1, Table1[Year] = MAX ( Table1[Year] ) )
)

Regards
Zubair

Please try my custom visuals

Works perfectly. Thank you so much!

nirvana_moksh
Impactful Individual
Impactful Individual

Why dont you Sort it by Year and add a Index Column Starting with 1 and increment by 1 in Power Query and then use something like :

 

CALCULATE(LASTNONBLANK(TABLE1(COLUMN,1),FILTER(TABLE1,TABLE 1INDEX = MIN(TABLE1INDEX)))

 

 

 

Thanks for the reply. Was able to sort and create the index, However, when I tried the DAX below

 

CALCULATE(LASTNONBLANK(TABLE1(COLUMN,1),FILTER(TABLE1,TABLE 1INDEX = MIN(TABLE1INDEX)))

 

It pulls the data associated with 1 in the Index column. For example, the new calculated column is always "AA" (which is the contractor indexed at 1).

 

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.