Forum Discussion
Determining fleet size with many variables
- 5 months ago
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.
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!