This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
hi,
I have a calculation like below:
KPI =
SWITCH ( MAX ( 'Fact'[Color] ),
"Green", 1,
"Grey", 0,
"Red", -1
)
For each line I have assigned a color (green, grey or red), so it looks like this:
But I want to change the formula, so when lower level will have 0 and 1 then total should be 1.
For example:
Line16 = 0
Line15 = 1
Total for those lines should be 1 (now it is 0).
Here is the list of all cases:
| Value1 | Value2 | Aggregation |
| 1 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | -1 | -1 |
| 0 | 0 | 0 |
| 0 | -1 | -1 |
| -1 | -1 | -1 |
Solved! Go to Solution.
I think this will work
Green Factor =
SWITCH (
TRUE (),
ISINSCOPE ( 'Table'[Line ID] ), [KPI],
ISINSCOPE ( 'Table'[Department ID] ),
VAR summaryTable =
ADDCOLUMNS ( VALUES ( 'Table'[Line ID] ), "@val", [KPI] )
VAR val1 =
MINX ( summaryTable, [@val] )
VAR val2 =
MAXX ( summaryTable, [@val] )
VAR result =
CALCULATE (
MAX ( 'Aggregation table'[Aggregation] ),
TREATAS (
{ val1, val2 },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
)
RETURN
result,
ISINSCOPE ( 'Table'[Area ID] ),
VAR summaryTable =
ADDCOLUMNS ( VALUES ( 'Table'[Department ID] ), "@val", [KPI] )
VAR val1 =
MINX ( summaryTable, [@val] )
VAR val2 =
MAXX ( summaryTable, [@val] )
VAR result =
CALCULATE (
MAX ( 'Aggregation table'[Aggregation] ),
TREATAS (
{ val1, val2 },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
)
RETURN
result,
ISINSCOPE ( 'Table'[Site ID] ),
VAR summaryTable =
ADDCOLUMNS ( VALUES ( 'Table'[Area ID] ), "@val", [KPI] )
VAR val1 =
MINX ( summaryTable, [@val] )
VAR val2 =
MAXX ( summaryTable, [@val] )
VAR result =
CALCULATE (
MAX ( 'Aggregation table'[Aggregation] ),
TREATAS (
{ val1, val2 },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
)
RETURN
result,
VAR summaryTable =
ADDCOLUMNS ( VALUES ( 'Table'[Site ID] ), "@val", [KPI] )
VAR val1 =
MINX ( summaryTable, [@val] )
VAR val2 =
MAXX ( summaryTable, [@val] )
VAR result =
CALCULATE (
MAX ( 'Aggregation table'[Aggregation] ),
TREATAS (
{ val1, val2 },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
)
RETURN
result
)
works as expected, thank you very much!
I have made 2 fixes in the TREATS function:
- added brackets to avoid In the function TREATAS the number of output columns (2) does not match the number of columns in the input table (1) error
- swapped variables val1 with val2 in to search for proper values from Aggregation table
After the changes it looks like this:
TREATAS (
{ ( val2 , val1 ) },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
I think this will work
Green Factor =
SWITCH (
TRUE (),
ISINSCOPE ( 'Table'[Line ID] ), [KPI],
ISINSCOPE ( 'Table'[Department ID] ),
VAR summaryTable =
ADDCOLUMNS ( VALUES ( 'Table'[Line ID] ), "@val", [KPI] )
VAR val1 =
MINX ( summaryTable, [@val] )
VAR val2 =
MAXX ( summaryTable, [@val] )
VAR result =
CALCULATE (
MAX ( 'Aggregation table'[Aggregation] ),
TREATAS (
{ val1, val2 },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
)
RETURN
result,
ISINSCOPE ( 'Table'[Area ID] ),
VAR summaryTable =
ADDCOLUMNS ( VALUES ( 'Table'[Department ID] ), "@val", [KPI] )
VAR val1 =
MINX ( summaryTable, [@val] )
VAR val2 =
MAXX ( summaryTable, [@val] )
VAR result =
CALCULATE (
MAX ( 'Aggregation table'[Aggregation] ),
TREATAS (
{ val1, val2 },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
)
RETURN
result,
ISINSCOPE ( 'Table'[Site ID] ),
VAR summaryTable =
ADDCOLUMNS ( VALUES ( 'Table'[Area ID] ), "@val", [KPI] )
VAR val1 =
MINX ( summaryTable, [@val] )
VAR val2 =
MAXX ( summaryTable, [@val] )
VAR result =
CALCULATE (
MAX ( 'Aggregation table'[Aggregation] ),
TREATAS (
{ val1, val2 },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
)
RETURN
result,
VAR summaryTable =
ADDCOLUMNS ( VALUES ( 'Table'[Site ID] ), "@val", [KPI] )
VAR val1 =
MINX ( summaryTable, [@val] )
VAR val2 =
MAXX ( summaryTable, [@val] )
VAR result =
CALCULATE (
MAX ( 'Aggregation table'[Aggregation] ),
TREATAS (
{ val1, val2 },
'Aggregation table'[Value 1],
'Aggregation table'[Value 2]
)
)
RETURN
result
)
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 27 | |
| 25 | |
| 25 | |
| 21 | |
| 14 |
| User | Count |
|---|---|
| 50 | |
| 44 | |
| 20 | |
| 18 | |
| 18 |