Forum Discussion
Min, max and Avg Row
Hi,
I have below data table in PBI -
| A | B | C | |
| US | 4,080 | 2,548 | 860 |
| SA | 5,897 | 2,191 | 421 |
| IN | 1,635 | 2,808 | 339 |
| UK | 754 | 1,359 | 629 |
I want to get Min, Max and Avg of column A, B and C in row like below in PBI -
| A | B | C | |
| US | 4,080 | 2,548 | 860 |
| SA | 5,897 | 2,191 | 421 |
| IN | 1,635 | 2,808 | 339 |
| UK | 754 | 1,359 | 629 |
| Min | 754 | 1,359 | 339 |
| Max | 5,897 | 2,808 | 629 |
| Avg | 2,260 | 2,083 | 484 |
How can I achieve that? Please help!
Anonymous ,
min A = Calculate(min(Table[A]),allselected(Table))
Max A = Calculate(Amx(Table[A]),allselected(Table))
And So on.
Another way is unpivoting the data A,B,C are the values of New Column Col1 (With A,b ,C), Value with Value
https://radacad.com/pivot-and-unpivot-with-power-bi
min = Calculate(min(Table[Value]),allexcept(Table,Table[Col1]))max = Calculate(max(Table[Value]),allexcept(Table,Table[Col1]))
Avg= Calculate(Average(Table[Value]),allexcept(Table,Table[Col1]))
display with Show on row in matrix
https://www.burningsuit.co.uk/blog/2019/04/7-secrets-of-the-matrix-visual/
Anonymous - You can either unpivot those columns or use MC Aggregations
- Anonymous5 years ago
Hi Anonymous,
I also think unpivoted columns should be a simple way to achieve your requirement.
If you not want to change your structure, you can try to use following calculate table formula. (I hard code these values into formulas and manually append these aggregated rows)Table= VAR temp = SELECTCOLUMNS ( { "Min", "Max", "Avg" }, "Region", [Value], "A", SWITCH ( [Value], "Min", MINX ( ALL ( 'Table'[A] ), [A] ), "Max", MAXX ( ALL ( 'Table'[A] ), [A] ), "Avg", AVERAGEX ( ALL ( 'Table'[A] ), [A] ) ), "B", SWITCH ( [Value], "Min", MINX ( ALL ( 'Table'[B] ), [B] ), "Max", MAXX ( ALL ( 'Table'[B] ), [B] ), "Avg", AVERAGEX ( ALL ( 'Table'[B] ), [B] ) ), "C", SWITCH ( [Value], "Min", MINX ( ALL ( 'Table'[C] ), [C] ), "Max", MAXX ( ALL ( 'Table'[C] ), [C] ), "Avg", AVERAGEX ( ALL ( 'Table'[C] ), [C] ) ) ) RETURN UNION ( 'Table', temp )Regards,
Xiaoxin Sheng
3 Replies
- amitchandakSuper User
Anonymous ,
min A = Calculate(min(Table[A]),allselected(Table))
Max A = Calculate(Amx(Table[A]),allselected(Table))
And So on.
Another way is unpivoting the data A,B,C are the values of New Column Col1 (With A,b ,C), Value with Value
https://radacad.com/pivot-and-unpivot-with-power-bi
min = Calculate(min(Table[Value]),allexcept(Table,Table[Col1]))max = Calculate(max(Table[Value]),allexcept(Table,Table[Col1]))
Avg= Calculate(Average(Table[Value]),allexcept(Table,Table[Col1]))
display with Show on row in matrix
https://www.burningsuit.co.uk/blog/2019/04/7-secrets-of-the-matrix-visual/
- Greg_DecklerCommunity Champion
Anonymous - You can either unpivot those columns or use MC Aggregations
- AnonymousNot applicable
Hi Anonymous,
I also think unpivoted columns should be a simple way to achieve your requirement.
If you not want to change your structure, you can try to use following calculate table formula. (I hard code these values into formulas and manually append these aggregated rows)Table= VAR temp = SELECTCOLUMNS ( { "Min", "Max", "Avg" }, "Region", [Value], "A", SWITCH ( [Value], "Min", MINX ( ALL ( 'Table'[A] ), [A] ), "Max", MAXX ( ALL ( 'Table'[A] ), [A] ), "Avg", AVERAGEX ( ALL ( 'Table'[A] ), [A] ) ), "B", SWITCH ( [Value], "Min", MINX ( ALL ( 'Table'[B] ), [B] ), "Max", MAXX ( ALL ( 'Table'[B] ), [B] ), "Avg", AVERAGEX ( ALL ( 'Table'[B] ), [B] ) ), "C", SWITCH ( [Value], "Min", MINX ( ALL ( 'Table'[C] ), [C] ), "Max", MAXX ( ALL ( 'Table'[C] ), [C] ), "Avg", AVERAGEX ( ALL ( 'Table'[C] ), [C] ) ) ) RETURN UNION ( 'Table', temp )Regards,
Xiaoxin Sheng