Define a date interval between start of month and today's date JMP16Good morning,
Since this morning I have encountered a problem with my script on JMP and I need your help please.
J'ai essayé de définir deux fonctions pour avoir la date de début de mois et la date d'aujourd'hui :
axe1:get_day_of_month- This function takes a date as input and returns the day of the month as a number.
axe1:get_dates- This function retrieves the start date of the current month and today's date.
Then a function to calculate:
//nb_total_ict and nb_total_fct: allow you to count the total number of tests carried out
//nb_nok_ict and nb_nok_fct: allow you to count the number of noks among all the tests
In order to calculate the NOK percentage for ICT and FCT between the start of the month and today's date.
Attached is a copy of part of my code.
I thank you in advance.
Sincerely,
Yass
// Fonction pour obtenir le jour du mois
axe1:get_day_of_month = Function({date},
day_of_month = Num(Format(date, "dd"));
day_of_month
);
// Fonction pour récupérer les dates
axe1:get_dates = Function({},
today_date = Format(Today(), "yyyy-mm-dd");
day_of_month = axe1:get_day_of_month(Today());
start_of_month = Format(Today() - (day_of_month - 1), "yyyy-mm-dd");
{start_of_month, today_date}
);
// Fonction pour calculer les pourcentages de NOK
axe1:calculate_nok_percentages = Function({dt},
{start_of_month, today_date} = axe1:get_dates();
// Initialisation des variables
nb_total_ict = 0;
nb_total_fct = 0;
nb_nok_ict = 0;
nb_nok_fct = 0;
// Récupération des lignes correspondant à la période spécifiée
FileRows = dt << Get Rows Where(
Num(Char(:Date)) >= Num(start_of_month) & Num(Char(:Date)) <= Num(today_date) & Contains(:File Name, "GOLDEN") == 0
);
total_rows = N Items(FileRows);
For(j = 1, j <= total_rows, j++,
If(dt:ICT_FCT[FileRows[j]] == "ICT",
nb_total_ict += dt:Nb_de_lignes[FileRows[j]];
If(dt:Result[FileRows[j]] == "NOK",
nb_nok_ict += dt:Nb_de_lignes[FileRows[j]]
)
);
If(dt:ICT_FCT[FileRows[j]] == "FCT",
nb_total_fct += dt:Nb_de_lignes[FileRows[j]];
If(dt:Result[FileRows[j]] == "NOK",
nb_nok_fct += dt:Nb_de_lignes[FileRows[j]]
)
);
);
// Calcul des pourcentages NOK
percent_nok_ict = (nb_nok_ict / nb_total_ict) * 100;
percent_nok_fct = (nb_nok_fct / nb_total_fct) * 100;
// Affichage des résultats
Window("Analyse des données") << Append(
V List Box(
Outline Box("Résultat NOK",
Border Box(
Text Box("Pourcentage de NOK ICT du " || start_of_month || " au " || today_date || " : " || Char(Round(percent_nok_ict, 2)) || "%"),
Text Box("Pourcentage de NOK FCT du " || start_of_month || " au " || today_date || " : " || Char(Round(percent_nok_fct, 2)) || "%")
)
)
)
);
);
Automation and ScriptingWindowsRe: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16What is the problem you are having (translation in the community might be incorrect as I couldn't really find the issue easily)? Most likely you want to use Date Difference() or Date Increment(). Use "month" as intervalname and "start" as alignment to get the first date of month. For example first date of this month
Date Increment(Today(), "Month", 0, "start");
JMP also has Month() to get the month of date and many more datetime functions which you might find useful for this type of work

Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16I tried to define two functions to get the start date of the month and today's date in order to calculate the percentage of NOK results in a table for ICT and FCT based on a date table (dt).
i did use
axe1:get_day_of_month - This function takes a date as input and returns the day of the month as a number.axe1:get_dates - This function gets the start date of the current month and today's date.axe1:calculate_nok_percentages - This function calculates the percentage of NOK results for ICT and FCT based on a date table (dt). It filters the data for rows where the file name does not contain "GOLDEN" and then calculates the percentage of NOK for ICT and FCT for the specified date range.
but every time i get this error message :
JMP Alert
The symbol evaluation is too recursive (>250 levels), on line 1 during access or evaluation of << start_of_month, start_of_month
on line 1
A stack overflow has been detected. The maximum number of call levels has been exceeded. Execution terminated on line 1
Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16I would guess the issue is with your For loop. Most likely it can be optimized and you won't even need to use a loop. If you already have the knowledge of the rows you can use for exampleData table subscripting to get the values you want from the table. You could also most likely use Subset + Summary to perform the calculations.
If you can provide a small example of your data (or mock up date) which can be used to demonstrate I can give more suggestions. Also if you can provide an example try to provide some information about the correct results.
Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16two possibilities, 2nd seems likely.
axe1:get_day_of_month = Function({date},
{ day_of_month },// 1: use local variables
day_of_month = Num(Format(date, "dd"));
day_of_month
);
// Fonction pour récupérer les dates
axe1:get_dates = Function({},
today_date = Format(Today(), "yyyy-mm-dd");
day_of_month = axe1:get_day_of_month(Today());
start_of_month = Format(Today() - (day_of_month - 1), "yyyy-mm-dd");
// 2: use evallist
evallist( {start_of_month, today_date} )
);
1: day_of_month may be global and may be confused between the functions
2: the list you return has the names of the variables, not the values, and they get stored into...themselves. I think that will be the recursion.
(Nice looking code!)
Re: Définir une intervalle de date entre début de mois jusqu'au la date d'aujourd'hui JMP16I would like to thank you for your suggestions and help.
I ended up modifying my get_dates function where i did get Today's date and start of month date and using a different For loop because I found some errors in the original loop. However, your suggestions were very helpful
that is the get_dates function :
axe1:get_dates = Function({},
today_date = Format(Today(), "yyyy-mm-dd");
start_of_month = Format(Date Increment(Today(), "Month", 0, "Start"), "yyyy-mm-dd");
evallist({start_of_month, today_date});
);Thanks again for everything !