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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
niziris
Frequent Visitor

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 mileage for different cars that are connected to components. 

My problem is because I slice mileage on component start and end date, when I plot component mileage it goes to 0 after end date. 
This mean that in the sum of mileage on all components there is a dip.

What I need is to push the last mileage on the end date, further till the end of Calendar. 

In the code below, when I use __convert it fills in for all Calendar dates, not just after the component_end, but if I put some number (for instance 500) then the whole thing is wokring and there is a flat line from compoenent_end till end of Calendar. 
I try to mimic simple number with casting measure as double but it didnt help. 
Any advice?

Thank you for your time

 

VAR __mileage_on_last_date =
    CALCULATE (
        MAX ( ft_aggregated[totalvehicledistancehighres_max] ),
        'Calendar'[Date] = __component_end) 
        
VAR __convert = CONVERT(__mileage_on_last_date, DOUBLE)
    
VAR __after_end_date =
    IF (
        TODAY() > __component_end,
        CALCULATE (
            __convert,
            FILTER (ALL ( 'Calendar' ), 'Calendar'[Date] >= __component_end)
        ),
        BLANK () 
    )

 

 

 

1 ACCEPTED SOLUTION
123abc
Community Champion
Community Champion

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.

View solution in original post

2 REPLIES 2
123abc
Community Champion
Community Champion

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.

Thank you 123abc for your time and effort! The solution was very close to what you said and you were on track to take MAX('Calendar'[Date])) as a limit. 
I will mark this as a Solution. 

Sorry for the delay in my response. 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.