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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Set a conditional flag

Hello!

 

I have a table where I have data on vehicle positions (vehicle id, time of sending their last position, longitude and latitude). I need to set up an active/inactive indicator (calculated column) to see if the vehicle has moved since the last position. The condition is that if there is a change (+/-) in latitude and/or longitude, the vehicle is defined as having been active, otherwise it is considered inactive. How can I write the condition ?

 

Greetings

1 ACCEPTED SOLUTION
PC2790
Community Champion
Community Champion

I mean use the given dax formula to create a calculated column in your table.Is that what you are doing?

Home-->New column-->Paste the code there

The error is because you are using it as a measure.

View solution in original post

7 REPLIES 7
PC2790
Community Champion
Community Champion

Hey @Anonymous ,

 

How does your sample data look like?

Anonymous
Not applicable

Here is a sample of my data @PC2790 

 

 

In this sample, the vehicles moved each time, so they are considered active.

 

But let’s imagine that the first line is duplicated with a different schedule, (the 04/07/2022 at 07:05:00 with the same longitude and latitude for example), the vehicle should therefore be marked as inactive for this newline

 

PC2790
Community Champion
Community Champion

Hey @Anonymous ,

 

Is this what you are looking for?

PC2790_0-1657884357259.png

Active/Inactive = 
var previousval = Calculate(Max(VehicleTb[PositionTimestamp]),Filter(VehicleTb,VehicleTb[PositionTimestamp]<Earlier(VehicleTb[PositionTimestamp])),ALLEXCEPT(VehicleTb,VehicleTb[Vehicle ID]))
var previouslong = CALCULATE(Max(VehicleTb[Long]),VehicleTb[PositionTimestamp] = previousval)
var previouslat = CALCULATE(Max(VehicleTb[Lat]),VehicleTb[PositionTimestamp] = previousval)
return
//previousval
if(VehicleTb[Long] = value(previouslong) && VehicleTb[Lat] = value(previouslat),"InActive","Active")
Anonymous
Not applicable

This seems perfect.

 

However, I don’t understand why certain fields are greyed out and not taken into account. Can you help me debug the formula @PC2790 ?

PC2790
Community Champion
Community Champion

This has to be a calculated column. Are you using the DAX in a calculated column?

Anonymous
Not applicable

No, these are not calculated columns,
The different fields work very well in the formula as you can see for positionTimestamp and the same for lontitude and longitude...

 

I don't unterstand the problem...

PC2790
Community Champion
Community Champion

I mean use the given dax formula to create a calculated column in your table.Is that what you are doing?

Home-->New column-->Paste the code there

The error is because you are using it as a measure.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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