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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Calculating a constant for the current filter context

Hi all,

 

I'm currently trying to make a measure that does a calculation for the last date of the current filter context (so for example, if we don't filter the calendar, it'll apply them to today's date, but if we choose Feb. 2021 for example, it'll calculate them for Feb 28th 2021)

 

 

Effectif:=

calculate([Calculation], filter(Sales,or(Sales[FlagActive]=1,max('Time'[idDay]) - Sales[idDayOfEntry] <4)))

 

 

However, that seems quite ineffective as it has to re-calculate the max(Time[idDay]) part for every iteration, whereas that's a constant for the current filter context.

 

Is there a way to calculate that whenever we change filter context, and just use it as a constant when we need it ?

 

Nossair

1 ACCEPTED SOLUTION

I don't think it is possible. It has no way to know that the filter context for date is going to be the same in every cell of a matrix or table visual, so it has to recalculate each time I think.

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

You can use a variable

Effectif :=
VAR maxDate =
    MAX ( 'Time'[idDay] )
RETURN
    CALCULATE (
        [Calculation],
        FILTER (
            Sales,
            OR ( Sales[FlagActive] = 1, maxDate - Sales[idDayOfEntry] < 4 )
        )
    )
Anonymous
Not applicable

Hi  @johnt75 ,

 

Thanks for your response. 

That doesn't seem to improve the performance, I think that's because that will still calculate the variable for every row that it calculates the measure for, whereas it'd be more optimal to calculate it once and then just use it as a constant without having to recalculate it. Do you have an idea if that is possible ?

I don't think it is possible. It has no way to know that the filter context for date is going to be the same in every cell of a matrix or table visual, so it has to recalculate each time I think.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.