Forum Discussion
Anonymous
4 years agoNot applicable
Conditional Formatting on Matrix Row level based on formula
Hi, Need a bit of dax help from the wizards. I'm trying to create a colour scale where the colour of a cell in a matrix table depends on the % increase/decrease from the previous value (in r...
- 4 years ago
Hi Majad,
This is an interesting one that I had to play around with a little. Anyone who can optimize this solution, please do.
Basically you create a measure in DAX to calculate the percentage between this month and last month first, then you base your conditional formatting on a field like so:
Here is the DAX measure I made to do this:
Change % = VAR cumulativeMinusOne = CALCULATE( SUM('Table'[Value]), PARALLELPERIOD('Calendar'[Date],-1,Month), 'Calendar'[Date] <= MAX('Table'[Year-Month])) VAR cumulativeMinusTwo = CALCULATE( SUM('Table'[Value]), PARALLELPERIOD('Calendar'[Date],-2,Month), 'Calendar'[Date] <= MAX('Table'[Year-Month])) VAR valueLastMonth = cumulativeMinusOne - cumulativeMinusTwo VAR valueThisMonth = SUM('Table'[Value]) VAR changePercentage = DIVIDE( valueThisMonth, valueLastMonth, BLANK() ) RETURN IF( DIVIDE( valueThisMonth, valueLastMonth, BLANK()) <> BLANK(), DIVIDE( valueThisMonth, valueLastMonth, BLANK()) -1, BLANK() )
MartijnW
4 years agoFrequent Visitor
Hi all,
As I suspected, the above example is far more complex than it needs to be. Please see this link for the usage of the function DATEADD(). Far more comprehensive.
You can quite easily replace the first three variables with this one function, that is meant for exactly this purpose.
Martijn