Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Allen_R
Frequent Visitor

Conditional Format Not Working on Matrix Total Row

I’m having to use the following DAX code as a conditional background measure to highlight the maximum values in each row within the matrix below.  All three variables within the matrix are table columns.  In other words, there are no measures in the matrix other than the measure that’s used as the conditional format.  The matrix is filtered from both page filters (line_of_business and year) and slicers (market, vice_president, kind_of_business, and week).

The main issue I’m having is that the maximum value within the Total row is not being highlighted for some reason, despite having the conditional format applied to both Values and Totals.  Any ideas on why that might be or how to correct it?  And because of how the DAX is written, I’m also running into situations where the maximum negative value is being highlighted over a 0 value, which is incorrect.  But if I change the IF statement from “> 0” to “>= 0”, then no negative values get highlighted.

 

DAX code used for conditional format:

 

is_max_weekly_gap_to_plan = 
VAR max_positive =
    CALCULATE(
        MAXX(
            FILTER(enterprise_combined, enterprise_combined[total_sales_vs_plan] >= 0),
            enterprise_combined[total_sales_vs_plan]
        ), ALLEXCEPT(enterprise_combined, enterprise_combined[area_name], enterprise_combined[line_of_business], enterprise_combined[kind_of_business])
    )

VAR max_negative =
    CALCULATE(
        MAXX(
            FILTER(enterprise_combined, enterprise_combined[total_sales_vs_plan] < 0),
            enterprise_combined[total_sales_vs_plan]
        ), ALLEXCEPT(enterprise_combined, enterprise_combined[area_name], enterprise_combined[line_of_business], enterprise_combined[kind_of_business])
    )

VAR max_value = IF(max_positive > 0, max_positive, max_negative)

RETURN
IF(SUM(enterprise_combined[total_sales_vs_plan]) = max_value, 1, 0)

 


This is an example of what I'm getting.  Nothing in the Total row is getting highlighted, and I circled the 0 that should be highlighted vs. the -1 that is highlighted:
Post Image.GIF

Any suggestions on how to get this to work correctly?

1 ACCEPTED SOLUTION
Allen_R
Frequent Visitor

I finally managed to get this to work as intended using the DAX code below.  My thanks to v-linyulu-msft for getting me on the right track!  As a result, I'm going to mark this post as complete.  However, I'm now trying to get the same results for a matrix that has nested rows consisting of senior_vice_president and vice_president as opposed to just area_name.  I'm hoping I can just tweak the DAX below to make that happen, but if anyone has any suggestions, it would be greatly appreciated.

 

is_max_gap_slt = 
VAR max_weekly_area_row = CALCULATE(MAX(enterprise_combined[total_sales_vs_plan]), FILTER(ALLSELECTED(enterprise_combined), enterprise_combined[area_name] = MAX(enterprise_combined[area_name])))
VAR max_weekly_total_row = MAXX(SUMMARIZE(ALLSELECTED(enterprise_combined), enterprise_combined[week], "_sumtotal", SUM(enterprise_combined[total_sales_vs_plan])), [_sumtotal])

RETURN

IF(ISFILTERED(enterprise_combined[area_name]), IF(SUM(enterprise_combined[total_sales_vs_plan]) = max_weekly_area_row, 1, 0), IF(SUM(enterprise_combined[total_sales_vs_plan]) = max_weekly_total_row, 1, 0))

 

View solution in original post

3 REPLIES 3
Allen_R
Frequent Visitor

I finally managed to get this to work as intended using the DAX code below.  My thanks to v-linyulu-msft for getting me on the right track!  As a result, I'm going to mark this post as complete.  However, I'm now trying to get the same results for a matrix that has nested rows consisting of senior_vice_president and vice_president as opposed to just area_name.  I'm hoping I can just tweak the DAX below to make that happen, but if anyone has any suggestions, it would be greatly appreciated.

 

is_max_gap_slt = 
VAR max_weekly_area_row = CALCULATE(MAX(enterprise_combined[total_sales_vs_plan]), FILTER(ALLSELECTED(enterprise_combined), enterprise_combined[area_name] = MAX(enterprise_combined[area_name])))
VAR max_weekly_total_row = MAXX(SUMMARIZE(ALLSELECTED(enterprise_combined), enterprise_combined[week], "_sumtotal", SUM(enterprise_combined[total_sales_vs_plan])), [_sumtotal])

RETURN

IF(ISFILTERED(enterprise_combined[area_name]), IF(SUM(enterprise_combined[total_sales_vs_plan]) = max_weekly_area_row, 1, 0), IF(SUM(enterprise_combined[total_sales_vs_plan]) = max_weekly_total_row, 1, 0))

 

v-linyulu-msft
Community Support
Community Support

Hi,@Allen_R 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1717569572331.png

vlinyulumsft_1-1717569581511.png

2. Below are the measure I've created for your needs:

 

Measure1 = 
CALCULATE(MAX('enterprise_combined'[total_sales_vs_plan]),FILTER(ALLSELECTED('enterprise_combined'),'enterprise_combined'[area_name]=MAX('enterprise_combined'[area_name])))

Measure = IF(MAX('enterprise_combined'[total_sales_vs_plan])=[Measure1],8,2)

 

3.Modify the display format:

vlinyulumsft_2-1717569655433.png

4.Here's my final result, which I hope meets your requirements.

vlinyulumsft_3-1717569671255.png

Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.


Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank you v-linyulu-msft!  This definitely solved one of the issues that I was having which was when a maximum negative value was highlighted over a 0 value.  So at least that part is now resolved, but would you know how to highlight the maximum value in the total row? 

 

I selected "Values and totals" in the "Apply to" field of the conditional format just to see if your method would work for the total row, and below is what I get, which is incorrect.  Despite it being incorrect, however, your method did highlight a few numbers in the total row which is progress over my method…..which wasn’t highlighting anything.

 

I tried to include a sampling of the dataset, but it errored out due to size limitations....and I don't see an option to include it as an attachment.

Post Image1.GIFPost Image2.GIF

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.