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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
gregsuash
Regular Visitor

Matrix - conditional formatting when 3 values in a row are negative

Hi All!

Unfortunately I am facing an issue and literally losing my mind trying to solve it. I have a matrix table and I want to conditional format it based on values that are for last 5 ISO weeks. I have a calculated column that is giving me true when there are last 5 weeks and it is working fine and dynamically.

Then I want to see if there are 3 negaitve values in a row in the column and if this contion is true - I want to color all 3 in RED.

Firt I tried to solve only last 3 weeks coloring not the 5 one to make it easier and learn how to do this but I failed...

image.png

Those are the results I've achieved when I tried to work on last 3 weeks. Here one before last is the only one that should be colored as red, rest should be grey in this scenario. I wanted to combine all three conditions and I reached a result as 1 for the proper row but only for total. 
I am new to PBI and maybe I am not understanding properly how the DAX works in such a measure. Can anyone advice something? 


I would appreciate any help!

 

Measures I used:

Current Year/Week =
LOOKUPVALUE (
'CALENDAR'[ISO Year/Week],
CALENDAR[Date], TODAY () - 7
) -- I used -7 because I want to have "current week" as last finished week which is week 6.

 

TestColoringNegative =
VAR currentweek = [Current Year/Week]
VAR cw =
CALCULATE ( [Measure Value], CALENDAR[ISO Year/Week] = currentweek )
VAR pw =
CALCULATE ( [Measure Value], CALENDAR[ISO Year/Week] = currentweek - 1 )
VAR pw2 =
CALCULATE ( [Measure Value], CALENDAR[ISO Year/Week] = currentweek - 2 )
VAR valuebynegative =
SWITCH ( TRUE (), cw < 0, 1, pw < 0, 1, pw2 < 0, 1, 0 )
RETURN
valuebynegative

 

TestColoringNegative2 =
VAR currentweek = [Current Year/Week]
VAR cw =
CALCULATE ( [Measure Value], CALENDAR[ISO Year/Week] = currentweek )
VAR pw =
CALCULATE ( [Measure Value], CALENDAR[ISO Year/Week] = currentweek - 1 )
VAR pw2 =
CALCULATE ( [Measure Value], CALENDAR[ISO Year/Week] = currentweek - 2 )
RETURN
IF ( cw < 0 && pw < 0 && pw2 < 0, 1, 0 )

 

Thanks,

Greg

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @gregsuash ,

 

Regardless the weeknum, you could create a measure to count the negative value for each row.

_count = CALCULATE(DISTINCTCOUNT('Table'[column]),FILTER(ALLSELECTED('Table'),'Table'[row]=SELECTEDVALUE('Table'[row])&&[Measure]<0))

Then create the condition measure based the count value.

color = IF([Measure]<0&&[_count]>=3,"red")

1.PNG

In your case, you could add weeknum condition to the first formula.

 

Best Regards,

Jay

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @gregsuash ,

 

Regardless the weeknum, you could create a measure to count the negative value for each row.

_count = CALCULATE(DISTINCTCOUNT('Table'[column]),FILTER(ALLSELECTED('Table'),'Table'[row]=SELECTEDVALUE('Table'[row])&&[Measure]<0))

Then create the condition measure based the count value.

color = IF([Measure]<0&&[_count]>=3,"red")

1.PNG

In your case, you could add weeknum condition to the first formula.

 

Best Regards,

Jay

lbendlin
Super User
Super User

It's much more complex than this. You will need to use temporary tables in your measure. 

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to work with. 

Ibendlin, 

is this something what you meant with virtual table? 

 

gregsuash_1-1645385014602.png

 

I used this summarize with add column in a measure but for a meantime I put is just as a table to see how it works. 

 

Is it possible somehow to limit the "1" that appears, when the sum of it is based on a product where the SUM is at least greater than 3 (I mean 1 should be only where I put the red rectangle rest should be 0).

Hi Ibendlin,
thank you for your answer.

I made some random data in xlsx and put it into pbix. 

 

ISO WeekProductPlanActualDiffValue 1
01.2022A12356671,84%
01.2022B3453242116,43%
01.2022C433564-131-3,31%
02.2022A5435433216,97%
02.2022B312232803,90%
02.2022C7655671983,86%
03.2022A8878761180,64%
03.2022B123545-422-0,29%
03.2022C4231233001,41%
04.2022A543675-132-4,11%
04.2022B6554434522092,97%
04.2022C6542234541971,56%
05.2022A13024308721,49%
05.2022B23402341,00%
05.2022C32154321-1106-2,91%
07.2022A403232138194,92%
07.2022B43267655-3329-1,30%
07.2022C54336575-1142-4,76%
06.2022A42346457-2223-1,90%
06.2022B7565543621293,55%
06.2022C76558766-1111-6,89%
08.2022A8764444443202,03%
08.2022B234514369092,58%
08.2022C12346535812,12%

 

Most of this values (especially the % ones) doesn't make any sense but we reach here a sample that we have 3 week in a row negative values so as a sample it is pretty ok I think.

 

gregsuash_0-1645270613901.png

Unfortunately I cannot paste pbix file here with relation and measures in calendar table 😞 

 

Best regards,

Greg

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.