Forum Discussion

GarethW's avatar
GarethW
Frequent Visitor
6 years ago
Solved

Conditional formatting of Matrix based on Total average

Hello

I am new to PowerBI and am in the process of migrating old manual reports to it.

 

One of these reports shows share of sales, by month (column) by product type (rows).

 

This has a heat map conditional format that compares any given cell (share of sales for a product for a month) to the total share of sales for that product for the total time period reported on. The under-index (lowest) starts from red, progresses to yellow (the same as the average) all the way up to green for the highest over-index against the average. So in the above, for row 1, April sees the highest index of purchases (4.8%) vs the total average for that product of 3.7%.

 

I have recreated the pivot-table as a matrix, which was simple enough.

 

But I can't find any way to match the same conditional formatting logic as my original excel pivot.

 

Is it even possible?

 

Thanks

  • Hi GarethW ,

     

    First of all let me apologize for the late response I must have missed this post on the multiple notifications I have.

     

    What I think I was abble to get it to work I have created 3 measures (this simplifies the tough process):

    % per category/month =
    DIVIDE (
        COUNT ( 'Table'[Region] );
        CALCULATE ( COUNT ( 'Table'[Region] ); ALLSELECTED ( 'Table'[Region] ) )
    )
    
    
    
    % Total/region =
    VAR temp_table =
        FILTER (
            SUMMARIZE (
                ALLSELECTED ( 'Table' );
                'Table'[Region];
                "@count"; COUNT ( 'Table'[Region] )
            );
            'Table'[Region] = MAX ( 'Table'[Region] )
        )
    VAR total_table =
        SUMMARIZE (
            ALLSELECTED ( 'Table' );
            'Table'[Region];
            "@count"; COUNT ( 'Table'[Region] )
        )
    RETURN
        DIVIDE ( SUMX ( temp_table; [@count] ); SUMX ( total_table; [@count] ) )
    
    
    
    % variation = [% per category/month]-[% Total/region]

     

    Now use the last measure to create your condittional formatting.

     

    As you can see on the image below the values that are equal to the region total are blank below are red and above are green.

     

    Check also the PBIX file attached.

     

    Once more I'm very sorry for the delay in the answer.

22 Replies

  • Hi GarethW ,

     

    Go to the conditional formatting select the color scale then do it based on value and choose diverging and the colors should give expected result.

     

    I have selected Average on summarization (but can be other as sum or max etc) because it's a simple table if you are using a measure it's not even asked.

     

    Regards,

    MFelix

    • GarethW's avatar
      GarethW
      Frequent Visitor

      Hi, thanks, but I have tried that and it doesn't work as there is no way for it to use the last 'total' column as a reference.

       

      The actual matrix is based on counts, and the display type was just changed to be based on 'Percentage of Column Total'

       

      What I need to be comparing in the heat map are the percentages being displayed, not the actual counts behind those, as the counts will vary depending on the month, I only care about the relative share for any given month, versus the over all share (which is that final 'Total' column)

      • MFelix's avatar
        MFelix
        Super User

        Hi GarethW ,

         

        Wasn't aware that you had the percentage of column total would though it was a summarization or a measure, you need to change you values in the matrix by the measure below and then use the formatting as refered previously:

        Percentage of colum = CALCULATE(COUNT('Table'[Product Type]))/ CALCULATE(COUNT('Table'[Product Type]);ALL('Table'[Product Type]))

        Regards,

        MFelix

  • I am not sure I got it completely. But please try.

    Once I right-click on the measure in the Visualization tab.  And choose conditional formatting. I can see the option for rule-based

     

     

    Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
    Thanks.

  • Step 1 :

     

    MAX_VALUE =
    VAR m =
    CALCULATE (
    MAXX ( SUMMARIZE ( Table_NAME,COLUMN_NAME), CALCULATE ( VALUE ) ),
    REMOVEFILTERS (COLUMN_NAME )
    )

     

     

    Step 2 :  MAX_COLOR= iF(VALUE=[MAX_VALUE],"#FFFF01","")

    Step 3 :  Using Comnditional Format with filed Value