Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi, I don't understand how my var PosNeg get the value for sign for each line of the table ?
I thougth that the var was "constant" in the code.
FV =
var PosNeg = MIN( MaTable[Signe])
var result =
switch ( SELECTEDVALUE(MaTable[Libellé]),
"A",sum(MaTable[Valeur])*PosNeg,
"B",sum(MaTable[Valeur])*PosNeg,
"C",sum(MaTable[Valeur])*PosNeg,
"D",sum(MaTable[Valeur])*PosNeg
)
return result
I 've got this result whith the Dax code :
Solved! Go to Solution.
Hi @GuillaumePower
Each cell in the table visual has it's own filter context. In you example the first cell is subjected to a filter context that contains 'Table'[Libelle] IN { "A" } and so on. Measures are evaluated in each cell independently, therefore, the variable will be evaluated differently in each cell based on its filter context. However, inside a particular cell the variable is evaluated only once and cannot be recalculated. For example, the following measure will return SUM ( 'Table'[Column1] ) and the ALL modifier will not have any effect on the variable as it will never be recalculated hence the first evaluation will always be returned.
Measure =
VAR A = SUM ( 'Table'[Column1] )
RETURN
CALCULATE ( A, ALL ( 'Table'[Column2] ) )
Hi @GuillaumePower
Each cell in the table visual has it's own filter context. In you example the first cell is subjected to a filter context that contains 'Table'[Libelle] IN { "A" } and so on. Measures are evaluated in each cell independently, therefore, the variable will be evaluated differently in each cell based on its filter context. However, inside a particular cell the variable is evaluated only once and cannot be recalculated. For example, the following measure will return SUM ( 'Table'[Column1] ) and the ALL modifier will not have any effect on the variable as it will never be recalculated hence the first evaluation will always be returned.
Measure =
VAR A = SUM ( 'Table'[Column1] )
RETURN
CALCULATE ( A, ALL ( 'Table'[Column2] ) )
It is constant in that it is only evaluated once within the measure, but the measure itself is being evaluated for each row of your table. If you want to get the minimum across all rows you need to use REMOVEFILTERS(),
FV =
VAR PosNeg =
CALCULATE ( MIN ( MaTable[Signe] ), REMOVEFILTERS () )
VAR result =
SWITCH (
SELECTEDVALUE ( MaTable[Libellé] ),
"A", SUM ( MaTable[Valeur] ) * PosNeg,
"B", SUM ( MaTable[Valeur] ) * PosNeg,
"C", SUM ( MaTable[Valeur] ) * PosNeg,
"D", SUM ( MaTable[Valeur] ) * PosNeg
)
RETURN
result
User | Count |
---|---|
21 | |
19 | |
12 | |
9 | |
7 |
User | Count |
---|---|
30 | |
27 | |
14 | |
13 | |
10 |