diff --git a/src/slurmctld/node_scheduler.c b/src/slurmctld/node_scheduler.c
index 5ce310b0f6404713a2938b2441eaeac724447257..0aa1c3963551d0228035ff14cc412b7c453b3c23 100644
--- a/src/slurmctld/node_scheduler.c
+++ b/src/slurmctld/node_scheduler.c
@@ -1682,9 +1682,11 @@ extern int select_nodes(struct job_record *job_ptr, bool test_only,
 	/* Set this guess here to give the user tools an idea
 	 * of how many nodes Slurm is planning on giving the job.
 	 * This needs to be done on success or not.  It means the job
-	 * could run on nodes.
+	 * could run on nodes.  We only set the wag once to avoid
+	 * having to go through the bit logic multiple times.
 	 */
-	if (select_bitmap) {
+	if (select_bitmap
+	    && ((error_code == SLURM_SUCCESS) || !job_ptr->node_cnt_wag)) {
 #ifdef HAVE_BG
 		xassert(job_ptr->select_jobinfo);
 		select_g_select_jobinfo_get(job_ptr->select_jobinfo,