Forum Discussion
RDF25087
3 years agoHelper I
Date Conditional formatting
Hi all - I have a column that looks at a date value and then returns: 1 if the field in the column is blank 2 if the date is less than 1 month old 3 if the date is between 1 and 3 months, a...
- 3 years ago
Try the following code:
Conditional Colour = VAR temptable = TOPN ( 1, 'Table', 'Table'[Last Sale Date], ASC ) VAR DateSelection = MAXX ( temptable, 'Table'[Last Sale Date] ) RETURN SWITCH ( TRUE (), COUNTROWS(temptable) = 0 , BLANK(), DateSelection= BLANK (), "Black", DATEDIFF ( DateSelection, TODAY (), MONTH ) < 1, "Green", DATEDIFF ( DateSelection, TODAY (), MONTH ) < 3, "Light Blue", "Red" )No use the condittional formatting from field value:
- 3 years ago
Hi RDF25087 ,
My bad, should be less than or equal to 1 redo the measure to:
Conditional Colour = VAR temptable = TOPN ( 1, 'Table', 'Table'[Last Sale Date], DESC) VAR DateSelection = MAXX ( temptable, 'Table'[Last Sale Date] ) RETURN SWITCH ( TRUE (), COUNTROWS(temptable) = 0 , BLANK(), DateSelection= BLANK (), "Black", DATEDIFF ( DateSelection, TODAY (), MONTH ) <= 1, "Green", DATEDIFF ( DateSelection, TODAY (), MONTH ) <= 3, "Blue", "Red" )Since the calculation is in months values above 0.5 round to 1and were not considered. You may need to make some more adjustments using rounding or similar but believe this may be enough:
RDF25087
3 years agoHelper I
This is how my table data looks. I've added the field format at the top:
| Text | Text | Decimal Number | Decimal Number | DATE |
| Customer | Product | Latitude | Longitude | Last Sale Date |
| Customer A | Product A | 57.145639 | -2.116231 | null |
| Customer A | Product B | 57.145639 | -2.116231 | null |
| Customer A | Product C | 57.145639 | -2.116231 | null |
| Customer B | Product A | 57.115432 | -2.078639 | 15/06/2023 |
| Customer B | Product B | 57.115432 | -2.078639 | 15/06/2023 |
| Customer B | Product C | 57.115432 | -2.078639 | 15/06/2023 |
| Customer B | Product D | 57.115432 | -2.078639 | 15/06/2023 |
| Customer C | Product A | 57.153437 | -2.147753 | 21/04/2023 |
| Customer C | Product B | 57.153437 | -2.147753 | 21/04/2023 |
| Customer C | Product C | 57.153437 | -2.147753 | 21/04/2023 |
| Customer D | Product A | 56.470032 | -2.969002 | 03/01/2022 |
| Customer D | Product B | 56.470032 | -2.969002 | 03/01/2022 |
| Customer D | Product C | 56.470032 | -2.969002 | 03/01/2022 |
| Customer D | Product D | 56.470032 | -2.969002 | 03/01/2022 |
The customer appears multiple times because of the different products. The Last Sale date is just the last date a sale was made to that customer - not for the specific product.
When plotted on a map, the points should be coloured as follows:
| Text | Text | Decimal Number | Decimal Number | DATE | |
| Customer | Product | Latitude | Longitude | Last Sale Date | Map Point Colour |
| Customer A | Product A | 57.145639 | -2.116231 | null | Black |
| Customer A | Product B | 57.145639 | -2.116231 | null | |
| Customer A | Product C | 57.145639 | -2.116231 | null | |
| Customer B | Product A | 57.115432 | -2.078639 | 15/06/2023 | Green |
| Customer B | Product B | 57.115432 | -2.078639 | 15/06/2023 | |
| Customer B | Product C | 57.115432 | -2.078639 | 15/06/2023 | |
| Customer B | Product D | 57.115432 | -2.078639 | 15/06/2023 | |
| Customer C | Product A | 57.153437 | -2.147753 | 21/04/2023 | Blue |
| Customer C | Product B | 57.153437 | -2.147753 | 21/04/2023 | |
| Customer C | Product C | 57.153437 | -2.147753 | 21/04/2023 | |
| Customer D | Product A | 56.470032 | -2.969002 | 03/01/2022 | Red |
| Customer D | Product B | 56.470032 | -2.969002 | 03/01/2022 | |
| Customer D | Product C | 56.470032 | -2.969002 | 03/01/2022 | |
| Customer D | Product D | 56.470032 | -2.969002 | 03/01/2022 |
Thanks for any help.
RDF