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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
PhilippeMuniesa
Resolver I
Resolver I

Calculate filter, with format or value

Hello,

In a powerPivot table. "CompletContratrem"


I have a "Brut" column, decimal number format.
And a measure "fx_Brut":=Sum([Brut])

and another "Année" column, Text format

 

example

 

nomBrutAnnée 
Titi1125,452020 
Toto3456,872021 
Tata3456,212020 
tete1765,122021 

 

I would like the "Brut"  total if "Année" = 2020,

I tried several solutions, but it stuck

I have already calculated a measure to get 2020 (the smallest year in the Year column)

 

Regul_N_1:=calculate(value(max(CompletContratrem[Année]))-1)

i get good 2020

But,

even though I converted the "Année" column to integer, the metric "fx_Brut_N_1"

 

fx_Brut_N_1:=calculate([fx_Brut];filter(CompletContratrem;CompletContratrem[Année] =[Regul_N_1]))

, returns me (empty)

 

 

If I leave the Year column as text, and I adapt the measure by converting Année with Value

 

fx_Brut_N_1:=calculate([fx_Brut];filter(CompletContratrem;Value(CompletContratrem[Année] )=[Regul_N_1]))

, I also have a value return (empty)

 

On the other hand, if I modify the measure and set a hard comparison criterion ex: 2020, it works.

 

fx_Brut_N_1:=calculate([fx_Brut];filter(CompletContratrem;Value(CompletContratrem[Année] )=2020))

, returns the correct value

but,

 

fx_Brut_N_1:=calculate([fx_Brut];filter(CompletContratrem;Value(CompletContratrem[Année] )=value([Regul_N_1])))
Always returns (empty)

 

I don't understand, I need explanations and help.

Thank for your help

 

Philippe

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @PhilippeMuniesa 

 
because there is contex transition. when you call for the measure inside the filter function, filter provides a row context and the implicite CALCULATE surrounding the measure convert the row context to a filter context. it compares 2021 vs 2021-1, and 2020 vs 2020-1, so blank is returned. 
This shall work:
fx_Brut_N_1:=
VAR _value = [Regul_N_1]
RETURN calculate([fx_Brut];filter(CompletContratrem;Value(CompletContratrem[Année] )=_value))
 
More info about context transition:

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @PhilippeMuniesa 

 
because there is contex transition. when you call for the measure inside the filter function, filter provides a row context and the implicite CALCULATE surrounding the measure convert the row context to a filter context. it compares 2021 vs 2021-1, and 2020 vs 2020-1, so blank is returned. 
This shall work:
fx_Brut_N_1:=
VAR _value = [Regul_N_1]
RETURN calculate([fx_Brut];filter(CompletContratrem;Value(CompletContratrem[Année] )=_value))
 
More info about context transition:

Thank a lot,

i will read the article on context transition that i don't know.

philippe

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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