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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Anonymous
Not applicable

DAX Formula

Hello everyone,

 

I need to recover the longitude referring to the previous time stamp

 

Here is an example of my data :

Identifiant  PositionTimeStampp OldPositionTimeStamp Long Lat OldLong OldLat
121/07/2022 14:50:00 21/07/2022 14:40:00 0,12928 46,80856 0,13119 46,80699
121/07/2022 14:40:00   0,13119 46,80699    
221/07/2022 13:50:00 21/07/2022 13:40:00 0,09237 47,25609 0,09208 47,25606
221/07/2022 13:40:00   0,09208 47,25606    

 

I did recover the old timestamp (see formula below). Now I wish I could recover and display the old longitude and the old latitude (value red)

 

My formula for timestamp is:

 

oldPositionTimeStamp = CALCULATE(MAX('TABLEPOSITION'[PositionTimestamp]),'TABLEPOSITION'[PositionTimestamp] < EARLIEST('TABLEPOSITION'[PositionTimestamp]),ALLEXCEPT('TABLEPOSITION','TABLEPOSITION'[IDENTIFIANT]))

 

 

I tried this formula to get the old longitude ans the same for the latitude :

 

var OldLong = CALCULATE(MAX('TABLEPOSITION'[Long]), 'TABLEPOSITION'[positionTimestamp] = oldPositionTimeStamp)
return previouslong

 

But I don’t get value in the column, do you have a solution ?

 

Best regards

1 ACCEPTED SOLUTION
PC2790
Community Champion
Community Champion

Hey @Anonymous ,

 

Please try this code to create new calculated column:

 

requiredLatValue =
VAR oldtimestamp =
    CALCULATE (
        MAX ( 'MyTable'[PositionTimestampp] ),
        MyTable[PositionTimeStampp] < EARLIEST ( MyTable[PositionTimeStampp] ),
        ALLEXCEPT ( 'MyTable', MyTable[Identifiant  ] )
    )
RETURN
    (
        CALCULATE (
            MAX ( MyTable[Lat] ),
            FILTER ( MyTable, MyTable[PositionTimeStampp] = oldtimestamp )
        )
    )
requiredLongValue =
VAR oldtimestamp =
    CALCULATE (
        MAX ( 'MyTable'[PositionTimestampp] ),
        MyTable[PositionTimeStampp] < EARLIEST ( MyTable[PositionTimeStampp] ),
        ALLEXCEPT ( 'MyTable', MyTable[Identifiant  ] )
    )
RETURN
    (
        CALCULATE (
            MAX ( MyTable[Long] ),
            FILTER ( MyTable, MyTable[PositionTimeStampp] = oldtimestamp )
        )
    )

 

The results will be as shown:

PC2790_0-1658745904183.png

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Thank you everyone for your solution, I was able to succeed with the solution of @PC2790

johnt75
Super User
Super User

You could create a couple of measures like

Old Lat =
VAR currentTimestamp =
    SELECTEDVALUE ( 'TABLEPOSITION'[Position Timestamp] )
RETURN
    CALCULATETABLE (
        SELECTCOLUMNS (
            TOPN ( 1, 'TABLEPOSITION', 'TABLEPOSITION'[Position Timestamp] ),
            "@val", 'TABLEPOSITION'[Lat]
        ),
        'TABLEPOSITION'[Position Timestamp] < currentTimestamp
    )

and then same again for longitude

arichard19
Resolver I
Resolver I

Try re-using your original line as follows ->

X = CALCULATE( MAX('Table'[Long]),'Table'[PositionTimeStampp] < EARLIEST('Table'[PositionTimeStampp]),ALLEXCEPT('Table','Table'[dentifiant ]))
This will result in 
arichard19_0-1658746001772.png

 

PC2790
Community Champion
Community Champion

Hey @Anonymous ,

 

Please try this code to create new calculated column:

 

requiredLatValue =
VAR oldtimestamp =
    CALCULATE (
        MAX ( 'MyTable'[PositionTimestampp] ),
        MyTable[PositionTimeStampp] < EARLIEST ( MyTable[PositionTimeStampp] ),
        ALLEXCEPT ( 'MyTable', MyTable[Identifiant  ] )
    )
RETURN
    (
        CALCULATE (
            MAX ( MyTable[Lat] ),
            FILTER ( MyTable, MyTable[PositionTimeStampp] = oldtimestamp )
        )
    )
requiredLongValue =
VAR oldtimestamp =
    CALCULATE (
        MAX ( 'MyTable'[PositionTimestampp] ),
        MyTable[PositionTimeStampp] < EARLIEST ( MyTable[PositionTimeStampp] ),
        ALLEXCEPT ( 'MyTable', MyTable[Identifiant  ] )
    )
RETURN
    (
        CALCULATE (
            MAX ( MyTable[Long] ),
            FILTER ( MyTable, MyTable[PositionTimeStampp] = oldtimestamp )
        )
    )

 

The results will be as shown:

PC2790_0-1658745904183.png

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors