This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hi there,
POV: car rental business with fleet sometimes moving from one location to another.
I've a fleet file which gives me the following data:
From this what I'm trying to calculate is the number of vehicles at each location, for each class for every date in the calendar (separate table).
I managed to calculate this pretty well using the dax formula below in a new column, however what I'm struggling with is the following:
- getting my fleet movement right - the logic is if the calendar date is < Due Back Date, then use Current Location, otherwise use Expected Return Location. At the moment the formula below does not work to account for this (but I suspect it is linked to my connections, see next problematic)
- I need to link this table to other tables to get my location and car class filters working. As we can only have one connection between tables, it either only filters on locations or car classes - any idea how I can link both so my filters work?
Solved! Go to Solution.
Hi @AlienBI ,
Thanks for reaching out to Microsoft Fabric Community.
I was able to reproduce your scenario in my environment and validate the behavior.
The issue with TREATAS occurs because it requires a fully qualified column reference from the model. In this case, the location is being calculated dynamically inside the measure, so it cannot be used directly with TREATAS.
To address this, the location logic needs to be evaluated within the measure and the filters applied inside the FILTER context.
Below is a working measure that resolved the issue:
Fleet Size Final =
VAR SelectedDate = MAX('Calendar'[Date])
VAR BaseTable =
ADDCOLUMNS(
'Fleet',
"Dynamic Location",
IF(
SelectedDate < 'Fleet'[ Due Back Date ],
'Fleet'[ Current Location ],
'Fleet'[ Expected Return Location ]
)
)
RETURN
CALCULATE(
DISTINCTCOUNT('Fleet'[Unit # ]),
FILTER(
BaseTable,
'Fleet'[ In Service Date ] <= SelectedDate &&
'Fleet'[ Out of fleet date] >= SelectedDate &&
[Dynamic Location] IN VALUES('DimLocation'[Location]) &&
'Fleet'[ Class ] IN
FILTER(
VALUES('DimCarClass'[Class]),
NOT ISBLANK('DimCarClass'[Class])
)
)
)
With this approach, the fleet movement logic works correctly. A vehicle is counted under its current location before the due back date and switches to the expected return location after that date.
I have also included screenshots demonstrating the expected behavior along with the PBIX file for your reference.
Hope this helps. Please reach out for further assistance.
Thank you.
Hello @AlienBI
Instead of creating a large intermediate table using GENERATE, you should calculate fleet size directly based on the selected date from your calendar. The key idea is that for any given date, a vehicle is considered “in fleet” if the selected date falls between its In Service Date and Out of Fleet Date. On top of that, you need to dynamically decide the location of that vehicle depending on whether the selected date is before or after the Due Back Date. This dynamic location cannot be stored physically in the model because it changes per date, so it has to be created virtually inside the measure.
Here is the complete working approach in one go
Fleet Size Final =
VAR SelectedDate = MAX('Calendar'[Date])
VAR BaseTable =
ADDCOLUMNS(
'Fleet',
"Dynamic Location",
IF(
SelectedDate < 'Fleet'[Due Back Date],
'Fleet'[Current Location],
'Fleet'[Expected Return Location]
)
)
RETURN
CALCULATE(
DISTINCTCOUNT('Fleet'[Unit #]),
FILTER(
BaseTable,
'Fleet'[In Service Date] <= SelectedDate &&
'Fleet'[Out of fleet date] >= SelectedDate
),
TREATAS(
VALUES('DimLocation'[Location]),
[Dynamic Location]
),
TREATAS(
VALUES('DimCarClass'[Class]),
'Fleet'[Class]
)
)
This solves both of your problems together. The movement logic now works correctly because the location is evaluated dynamically for each date instead of being fixed in a calculated table, so if a vehicle jumps from stage/location 1 directly to 3 or 4, it still behaves correctly. At the same time, your filtering issue is resolved because you are no longer relying on a single physical relationship; instead, you use proper dimension tables for Location and Car Class and apply them using TREATAS, which allows both filters to work simultaneously even though the location is dynamically computed.
The reason your original approach was failing is because calculated tables and columns are evaluated at data refresh time, not at query time, so they cannot respond properly to slicers like date, location, or class. Also, using GENERATE with Calendar creates a heavy dataset and complicates relationships, which is unnecessary here.
hi @pankajnamekar25
Thanks a lot for this - it makes a lot of sense. But I'm having an issue with TREATAS as it requires a fully qualified column reference as argument number 2 - see error below.
Hi @AlienBI ,
Thanks for reaching out to Microsoft Fabric Community.
I was able to reproduce your scenario in my environment and validate the behavior.
The issue with TREATAS occurs because it requires a fully qualified column reference from the model. In this case, the location is being calculated dynamically inside the measure, so it cannot be used directly with TREATAS.
To address this, the location logic needs to be evaluated within the measure and the filters applied inside the FILTER context.
Below is a working measure that resolved the issue:
Fleet Size Final =
VAR SelectedDate = MAX('Calendar'[Date])
VAR BaseTable =
ADDCOLUMNS(
'Fleet',
"Dynamic Location",
IF(
SelectedDate < 'Fleet'[ Due Back Date ],
'Fleet'[ Current Location ],
'Fleet'[ Expected Return Location ]
)
)
RETURN
CALCULATE(
DISTINCTCOUNT('Fleet'[Unit # ]),
FILTER(
BaseTable,
'Fleet'[ In Service Date ] <= SelectedDate &&
'Fleet'[ Out of fleet date] >= SelectedDate &&
[Dynamic Location] IN VALUES('DimLocation'[Location]) &&
'Fleet'[ Class ] IN
FILTER(
VALUES('DimCarClass'[Class]),
NOT ISBLANK('DimCarClass'[Class])
)
)
)
With this approach, the fleet movement logic works correctly. A vehicle is counted under its current location before the due back date and switches to the expected return location after that date.
I have also included screenshots demonstrating the expected behavior along with the PBIX file for your reference.
Hope this helps. Please reach out for further assistance.
Thank you.
Thanks heaps, that works like a charm!
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 39 | |
| 28 | |
| 28 | |
| 22 | |
| 18 |
| User | Count |
|---|---|
| 67 | |
| 37 | |
| 32 | |
| 27 | |
| 25 |