Forum Discussion

waldnerr's avatar
waldnerr
Helper I
5 years ago
Solved

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

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

3 Replies

  • v-chenwuz-msft's avatar
    v-chenwuz-msft
    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.