Forum Discussion

niziris's avatar
niziris
Frequent Visitor
2 years ago
Solved

Forcing measure constant value after end_date

In my table, I have different components with start_date and end_date. There is a column with component_active_dates. Active dates are connected from Calendar table. Also there is another table with...
  • 123abc's avatar
    2 years ago

    It seems like you're trying to handle the scenario where the mileage for a component remains constant after its end date until the end of the calendar period. You want to ensure that when you plot the mileage of components, it doesn't drop to zero after the end date but rather stays constant until the end of your calendar.

    Your approach is mostly correct, but you're encountering issues with the calculation logic. Let's refine your DAX code:

     

    VAR __mileage_on_last_date =
    CALCULATE (
    MAX ( ft_aggregated[totalvehicledistancehighres_max] ),
    FILTER (ft_aggregated, ft_aggregated[component_active_dates] <= MAX('Calendar'[Date]))
    )

    VAR __after_end_date =
    IF (
    TODAY() > __component_end,
    __mileage_on_last_date,
    BLANK()
    )

    RETURN
    __after_end_date

     

    Here's what each part of the DAX code does:

    1. __mileage_on_last_date: This variable calculates the maximum mileage for the component until the last date available in the calendar. This is achieved by filtering the mileage data up to the maximum date available in the calendar.

    2. __after_end_date: This variable checks if the current date is greater than the component's end date. If it is, it returns the value of __mileage_on_last_date, effectively making the mileage constant after the end date. Otherwise, it returns BLANK().

    3. Finally, the RETURN statement returns the value of __after_end_date.

    Make sure that your ft_aggregated table is properly filtered to include only the relevant mileage data for the component you are analyzing. Adjust the filters and relationships according to your data model if needed.

     

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

     

    In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.