Forum Discussion
Conditional Formatting & Group By
- 7 years ago
Anonymous Man, this one does not want to give in! :smileyhappy:
I am guessing you have filters from other tables flowing into your visual which I think is causing the problem. I have updated the measure and as far as I can tell it is working with all scenarios.Fomatting Measure = VAR CurrentID = SELECTEDVALUE(Table1[ID]) VAR FilteredCount = CALCULATE( COUNTROWS ( FILTER ( VALUES(Table1[ID]), Table1[ID] > CurrentID ) ),ALLSELECTED() ) + 1 VAR FilterTrap = COUNTROWS(VALUES(Table1[ID])) RETURN IF ( NOT ISBLANK( FilterTrap ), IF ( ISINSCOPE(Table1[ID]), IF ( ISODD ( FilteredCount ), "#7195BE", "#68CCE4" ) ) )Sample file here: https://www.dropbox.com/s/y230n9u0wo08wjp/IDFormatting.pbix?dl=0
Here is a view with filters applied from both the table itself and from a related date table and it still works.A calculated column is not an option because the calc is static and if you filtered out an even row but left the two odd rows on either side the calculated column would not update to change the coloring. Our measure will since it is a count based on the visable IDs.
jdbuchanan71
EDIT:
Sorry, not working well as I thought.
Maybe I am missing something?
For example (Table sorted by ID)
Amazing!
Can you please explain the logic behind the DAX?
Reading it again and again for the last 10 minutes, and not sure I understand it completely.
Understood the basic logic of counting the rows until current row, but want a more technical explanation, if possible.
Thanks a lot,
A
COUNTROWS works over a table.
FILTER returns a table
Our filter returns a table of ALL ID's that are > the current ID, then we count that. We add 1 because if we don't, on the highest ID it returns a blank.
We then turn the count into a 1 / 2 based on even or odd.
If you want to see the steps working you can change the Return statement in the formula.
FormattingColumn =
VAR CurrentID = Table1[ID]
VAR IDCount =
COUNTROWS(
FILTER (
ALL ( Table1[ID] ), Table1[ID] > CurrentID) ) + 1
--Return IF( ISODD ( IDCount ) , 1, 2 )
Return IDCountIn the code above I commented out the switch and returned the IDCount variable instead.