Forum Discussion
Display when the difference between two dates reaches a threshold for lines having a common value
- Anonymous3 years ago
After some tests, I decided to stick with the command below to detect the changes. It returns "sans donnée" to signal the companies for which there is no data after or before the dates of comparison.
Many thanks again to v-henryk-mstf ; you really did 99% of the heavy lifting and it helped a lot !
I wish a great day to everybody,
Augmentation_employee_count_entre_2_dates =
VAR seuil = 5 //augmentation en pourcentage, 20 signifie +20%
VAR date_after =
DATE ( 2022, 10, 01 ) //date Ă partir de laquelle on regarde le changement
VAR date_before =
DATE ( 2022, 09, 01 ) //date de référence
VAR after_ =
CALCULATE (
MAX ( 'Table'[employees_count] ),
FILTER (
ALL ( 'Table' ),
'Table'[company_name] = EARLIER ( 'Table'[company_name] )
&& 'Table'[updated_at] > date_after
)
)
VAR before_ =
CALCULATE (
MAX ( 'Table'[employees_count] ),
FILTER (
ALL ( 'Table' ),
'Table'[company_name] = EARLIER ( 'Table'[company_name] )
&& 'Table'[updated_at] < date_before
)
)
RETURN
IF (
after_ = 0,
"sans donnée",
IF (
before_ = 0,
"sans donnée",
IF ( after_ / before_ > ( 1 + ( seuil / 100 ) ), "oui", "non" )
)
)
Many thanks, for your precious help v-henryk-mstf . It is greatly appreciated đ
I shared below, a small sample of the data. I added on the sample, the expected result.
I could create a new column âResultâ. It runs, no syntax error detected, but the result is quite different from expected :
- I have lines that are âYESâ, however there is only one line for the company so there canât be a comparison. For instance â2° Investing Initiativeâ.
- The few expected âYESâ are not identified. For instance â2Empowerâ.
- On the contrary, there are companies identified âYESâ while they shouldnât. For instance â73 Stringsâ.
Here is your script, adapted to my real database labels :
Result =
VAR after_ =
CALCULATE (
SUM ( 'Table'[employees_count]),
FILTER (
ALL ( 'Table' ),
'Table'[company_name] = EARLIER ( 'Table'[company_name] )
&& 'Table'[updated_at] > DATE ( 2022, 10, 01 )
)
)
VAR before_ =
CALCULATE (
SUM ( 'Table'[employees_count]),
FILTER (
ALL ( 'Table' ),
'Table'[company_name] = EARLIER ( 'Table'[company_name] )
&& 'Table'[updated_at] < DATE ( 2022, 05, 30 )
)
)
RETURN
IF ( after_ / before_ > 10, "YES", "No" )
Do you see where the error could originate ?
I noticed that the result doesn't change when the threshold in line 21 change.
Many thanks for your help,
------------------------------------------------------------------------------------------------------------------
Sample :
| company_name | employees_count | updated_at | expected result |
| 2Empower | 57 | 2022-08-21 07:56:16 | YES |
| 2Empower | 85 | 2022-09-22 15:46:42 | YES |
| â€ïžPositive thought âïž Daily Good News | 750 | 2022-06-30 09:03:33 | YES |
| â€ïžPositive thought âïž Daily Good News | 845 | 2022-08-23 08:35:18 | YES |
| â€ïžPositive thought âïž Daily Good News | 845 | 2022-08-23 11:17:16 | YES |
| 2° Investing Initiative | 40 | 2022-10-04 10:59:20 | No |
| 73 Strings | 45 | 2022-08-21 08:02:40 | No |
| 73 Strings | 46 | 2022-08-28 08:01:52 | No |
| 73 Strings | 46 | 2022-09-22 15:54:29 | No |
| 73 Strings | 47 | 2022-10-04 10:45:28 | No |
| A l'écoute d'opportunités | 21 | 2022-10-13 16:15:51 | No |
| . | 136 | 2022-10-04 07:39:50 | No |
| . | 135 | 2022-10-06 07:39:11 | No |
Result:
| company_name | employees_count | updated_at | Result |
| 2Empower | 57 | 2022-08-21 07:56:16 | No |
| 2Empower | 85 | 2022-09-22 15:46:42 | No |
| â€ïžPositive thought âïž Daily Good News | 750 | 2022-06-30 09:03:33 | No |
| â€ïžPositive thought âïž Daily Good News | 845 | 2022-08-23 08:35:18 | No |
| â€ïžPositive thought âïž Daily Good News | 845 | 2022-08-23 11:17:16 | No |
| 2° Investing Initiative | 40 | 2022-10-04 10:59:20 | YES |
| 73 Strings | 45 | 2022-08-21 08:02:40 | YES |
| 73 Strings | 46 | 2022-08-28 08:01:52 | YES |
| 73 Strings | 46 | 2022-09-22 15:54:29 | YES |
| 73 Strings | 47 | 2022-10-04 10:45:28 | YES |
| A l'écoute d'opportunités | 21 | 2022-10-13 16:15:51 | YES |
| . | 136 | 2022-10-04 07:39:50 | YES |
| . | 135 | 2022-10-06 07:39:11 | YES |