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

Lookup latest value

Hi,

 

i would like create a calculated column called "Program Name" in the "Global Project" for each GlobalProjectKey.

The relevant value is stored in the table "Custom Fields", column "Program Name". 

I would like to select the value with the latest "Date Key" value from the "Project Period" table for each "Globalprojectkey" value.

 

 

"Global Project" table:

GlobalprojectkeyProgram Name
AProgram A
BProgram C

 

1: N (via GlobalProjectKey)

 

"Project Period" table:

GlobalProjectKeyDatekeyProjectPeriodKey
A08/2021Key 1
A07/2021Key 2
B08/2021Key 3
B07/2021Key 4
B06/2021Key 5

 

1:N (via ProjectPeriodKey)

 

"Custom Fields" table:

GlobalProjectKeyProjectperiodKeyProgram NameOther Column AOther Column B
AKey 1Program A  
AKey 1 Other 0 
AKey 2 Other 1 
AKey 2  Other 2
AKey 2Program B  
BKey 3Program C 

 

 

BKey 4Program D 

 

BKey 5Program E 

 

 

I tried to solve this via the LOOKUPVALUE function but wasn't sucessfull, because i was not to able to select the value with the latest datekey per project from the project period table.

I would apprechiate your help to find a solution.

 

Thank you,

Best regards,

Reinhard

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi waldnerr,

 

You can try this new column, it is a little long.

Program Name =
var LastestDate = 
CALCULATE(
    MAX('Project Period'[Datekey]),
    FILTER('Project Period',[GlobalProjectKey]=EARLIER('Global Project'[Globalprojectkey]))
)
var LastestKey = 
CALCULATE(
    MAX('Project Period'[ProjectPeriodKey]),
    FILTER('Project Period',[Globalprojectkey]=EARLIER('Global Project'[Globalprojectkey]) && [Datekey]=LastestDate)
)
RETURN
CALCULATE(
    MAX('Custom Fields'[Program Name]),
    FILTER('Custom Fields',[Globalprojectkey]=EARLIER('Global Project'[Globalprojectkey]) && [ProjectperiodKey]=LastestKey)
)

 

Here's the file I made with your data, you can try it.

 

 

Best Regards

Community Support Team _ chenwu zhu

 

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

3 REPLIES 3
v-chenwuz-msft
Community Support
Community Support

Hi waldnerr,

 

You can try this new column, it is a little long.

Program Name =
var LastestDate = 
CALCULATE(
    MAX('Project Period'[Datekey]),
    FILTER('Project Period',[GlobalProjectKey]=EARLIER('Global Project'[Globalprojectkey]))
)
var LastestKey = 
CALCULATE(
    MAX('Project Period'[ProjectPeriodKey]),
    FILTER('Project Period',[Globalprojectkey]=EARLIER('Global Project'[Globalprojectkey]) && [Datekey]=LastestDate)
)
RETURN
CALCULATE(
    MAX('Custom Fields'[Program Name]),
    FILTER('Custom Fields',[Globalprojectkey]=EARLIER('Global Project'[Globalprojectkey]) && [ProjectperiodKey]=LastestKey)
)

 

Here's the file I made with your data, you can try it.

 

 

Best Regards

Community Support Team _ chenwu zhu

 

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

@v-chenwuz-msft 

Thank you, your proposed solution works perfectly.

@Greg_Deckler 

Thank you too for your valuable input.

Greg_Deckler
Super User
Super User

@waldnerr Seems like you want Lookup Min/Max - Microsoft Power BI Community


@ 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...

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.