Forum Discussion
Color matrix by column total
- 4 years ago
Hi, afbraga66
You can try:
Color Measure = var c =SUMMARIZE(ALLSELECTED(DOWNTIME),DOWNTIME[NOME_TIPO],DOWNTIME[MES_FABRIL],"sum",SUM(DOWNTIME[Duration Minutes])) var a =MAXX(FILTER(c,[MES_FABRIL]=SELECTEDVALUE(DOWNTIME[MES_FABRIL])),[sum]) var b =MINX(FILTER(c,[MES_FABRIL]=SELECTEDVALUE(DOWNTIME[MES_FABRIL])),[sum]) return IF(ISINSCOPE(DOWNTIME[NOME_TIPO])&&NOT(ISINSCOPE(DOWNTIME[COD_OP])),SWITCH(TRUE(),[mDuration(min)]=a,"Red",[mDuration(min)]=b,"Green","Orange"))I use summraize funtion to generate a virtual table with the same values like your matrix visual then use it to calculate.
If you use expand or collapse, you can use isinscope funtion or isfilter funtion to calculate the results of the main and hierarchical levels separately.
There is no one-time formula. When you use matrix visualization and have multiple row fields, the context becomes more complicated, and the code needs to be modified as the logic changes.
SUMMARIZE function (DAX) - DAX | Microsoft Docs
ISINSCOPE function (DAX) - DAX | Microsoft Docs
Did I answer your question ? Please mark my reply as solution. Thank you very much.
Best Regards,Community Support Team _ Janey
Hi, afbraga66
You should know that the measure in powerbi is very flexible, especially when you want to calculate dynamic values instead of fixed values. A little difference in context may cause different results.
If you can't provide some complete sample files or modify them according to my code, it is difficult for us to really help you.
If you have any questions about my code, please ask questions.
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
Best Regards,
Community Support Team _ Janey
Hello v-janeyg-msft
Hope you had a good rest đŸ™‚
So I set up a test file with the formula you provided, but still I wasn't able to get always the same result based on filters change. I also tried the conditions in the MAXX and MINX, but I get syntax error.
File below:
I have not understood so far the proper way to deal with filters when creating a formula, since it gives different results if I change filters. I expected always the same result, the higher value painted in red, the lower in green, the middle in something else.
Thank you.
Best regards,
André
- v-janeyg-msft4 years agoCommunity Support
Hi, afbraga66
You can try:
Color Measure = var c =SUMMARIZE(ALLSELECTED(DOWNTIME),DOWNTIME[NOME_TIPO],DOWNTIME[MES_FABRIL],"sum",SUM(DOWNTIME[Duration Minutes])) var a =MAXX(FILTER(c,[MES_FABRIL]=SELECTEDVALUE(DOWNTIME[MES_FABRIL])),[sum]) var b =MINX(FILTER(c,[MES_FABRIL]=SELECTEDVALUE(DOWNTIME[MES_FABRIL])),[sum]) return IF(ISINSCOPE(DOWNTIME[NOME_TIPO])&&NOT(ISINSCOPE(DOWNTIME[COD_OP])),SWITCH(TRUE(),[mDuration(min)]=a,"Red",[mDuration(min)]=b,"Green","Orange"))I use summraize funtion to generate a virtual table with the same values like your matrix visual then use it to calculate.
If you use expand or collapse, you can use isinscope funtion or isfilter funtion to calculate the results of the main and hierarchical levels separately.
There is no one-time formula. When you use matrix visualization and have multiple row fields, the context becomes more complicated, and the code needs to be modified as the logic changes.
SUMMARIZE function (DAX) - DAX | Microsoft Docs
ISINSCOPE function (DAX) - DAX | Microsoft Docs
Did I answer your question ? Please mark my reply as solution. Thank you very much.
Best Regards,Community Support Team _ Janey
- v-janeyg-msft4 years agoCommunity Support
Hi, afbraga66
Try this:
Color Measure = var c=SUMMARIZE(ALLSELECTED(DOWNTIME),DOWNTIME[NOME_TIPO],DOWNTIME[MES_FABRIL],"sum",SUM(DOWNTIME[Duration Minutes])) var a =MAXX(FILTER(c,[MES_FABRIL]=SELECTEDVALUE(DOWNTIME[MES_FABRIL])),[sum]) var b =MINX(FILTER(c,[MES_FABRIL]=SELECTEDVALUE(DOWNTIME[MES_FABRIL])),[sum]) return SWITCH(TRUE(),[mDuration(min)]=a,"Red",[mDuration(min)]=b,"Green","Orange")Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
Best Regards,Community Support Team _ Janey
- afbraga664 years agoHelper III
Hey v-janeyg-msft ,
This works indeed, thank you so much.
I have an additional doubt how do we deal when we have more than one row field in a pivot table?
I tried to add a new row field and it doesn't work anymore. I added the new field to the measure, but then it only works when the table is fully expanded. How can we make sure it works correctly in all different expand or collapse combinations?
Thank you.
I have added a file below.
Best regards,
André