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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sivarammoto
Frequent Visitor

Alternate row colour after 7 rows/after each new group

Hi All,

 

I have a requirement of showing alternate row colour in a table after every 7 rows. Below is an example . For the first 7 rows i would like to have background color is grey and the next 7 rows it is blue and again for next 7 rows it is grey so on... I have explored conditional formating but am not able to get in to there. Request your expert views in solving this.

S. NoTypeQty
1Opening10
1Received5
1AAA0
1BBB0
1CCC0
1Sold5
1Closing10
2Opening15
2Received5
2AAA0
2BBB0
2CCC0
2Sold5
2Closing15
3Opening10
3Received5
3AAA0
3BBB0
3CCC0
3Sold5
3Closing10
4Opening15
4Received5
4AAA0
4BBB0
4CCC0
4Sold5
4Closing15
 

 

1 ACCEPTED SOLUTION

hi, @sivarammoto 

If each [S.No] in visual all have 7 rows, If so, just try this way:

Use RANKX Function to add a rank measure for [S.No], and then use IsEven Function nested it.

EvenOdd = IF(ISEVEN(RANKX(ALLSELECTED('Table'),CALCULATE(SELECTEDVALUE('Table'[S. No])),,ASC,Dense)) = TRUE(),1,0)
Then use conditional formatting based on that measure, change minimum to number 0 and maximum to number 1 and then choose color. 
you could also add a mapping rank table for [S.No], then use it for rank measure.
 
If each [S.No] in visual don't all have 7 rows, for example:
[S.No]=1 only has 5 rows, [S.No]=2 has 7 rows, what is the expected output?
1. when you want the output is still the same each [S.No]
Do the same logic as above.
 
2. when you want the output is alternate row colour after 7 rows, just adjust the formula as below:
Measure = 
IF(ISEVEN(INT((RANKX(ALLSELECTED('Table'),CALCULATE(SELECTEDVALUE('Table'[S. No])&SELECTEDVALUE('Table'[Type])),,ASC,Dense)-1)/7)) = TRUE(),1,0)
 
best regards,
Lin

 

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

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

One way to solve this is with a measure: 

EvenOdd = IF(ISEVEN(SELECTEDVALUE(Table1[S. No])) = TRUE();1;0)
 
Then use conditional formatting based on that measure, change minimum to number 0 and maximum to number 1 and then choose color. 
Downside is you have to do it for each column seperately.
 
Hope it helps!

Hi Andy,

 

Thanks for your quick reply.. 

S.No which i mentioned in my example was dummy data. In real scenario S.No will be like "ABC7089010". So "IsEven" function will not be useful. I have also tried "Mod" function but that is not working.  I am exploring permanent solution where if i add new column also it should work instead of applying conditional format on each columnn seperately

hi, @sivarammoto 

If each [S.No] in visual all have 7 rows, If so, just try this way:

Use RANKX Function to add a rank measure for [S.No], and then use IsEven Function nested it.

EvenOdd = IF(ISEVEN(RANKX(ALLSELECTED('Table'),CALCULATE(SELECTEDVALUE('Table'[S. No])),,ASC,Dense)) = TRUE(),1,0)
Then use conditional formatting based on that measure, change minimum to number 0 and maximum to number 1 and then choose color. 
you could also add a mapping rank table for [S.No], then use it for rank measure.
 
If each [S.No] in visual don't all have 7 rows, for example:
[S.No]=1 only has 5 rows, [S.No]=2 has 7 rows, what is the expected output?
1. when you want the output is still the same each [S.No]
Do the same logic as above.
 
2. when you want the output is alternate row colour after 7 rows, just adjust the formula as below:
Measure = 
IF(ISEVEN(INT((RANKX(ALLSELECTED('Table'),CALCULATE(SELECTEDVALUE('Table'[S. No])&SELECTEDVALUE('Table'[Type])),,ASC,Dense)-1)/7)) = TRUE(),1,0)
 
best regards,
Lin

 

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

Thanks Lin,

Your solution is working fine. However in this case i have to apply conditional formatting for every column, is there any way that i can create a variable and assign that variable at row level so that even if i add new column also it works .

 

Regards

Siva

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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