2 Samuel 24:10 David’s conscience troubled him after he had taken a census of the troops. He said to the Lord, “I have sinned greatly in what I’ve done. Now, Lord, because I’ve been very foolish, please take away your servant’s guilt.”
The census took 9 months and 20 days and then some time to tabulate the result and it was not until receiving the results that David was convicted by the Holy Spirit A of his sin. Maybe he realized that they had not collected the required tax from each man of 1/2 shekel and that God had said that would result in a plague. B Or maybe he realized that Joab had been right about warning him not to take the census. C
Whatever the reason David confessed his sin and sought the Lord’s forgiveness. When he confessed his sins of adultery and murder, David said, “I have sinned”; but when he confessed his sin of the census, he said, “I have sinned greatly”.
Most of us would consider his sins relating to Bathsheba far worse than the sin of the census. David’s sins with Bathsheba took the lives of four of David’s sons [the baby, Amnon, Absalom, and Adonijah] plus the life of Uriah, Ahithophel, and the 20,000 troops in the battle to reclaim the throne. After the census, God sent a plague that took the lives of 70,000 people. This may be a confirmation that the sin was greater.
There are 2 lessons for us today;  be very careful to seek guidance from the Holy Spirit, the Bible, the mind of Christ and others when making decisions,  and keep short accounts in self-examination for sin on a daily basis. David had at least ten months when he could have stopped the census but waited until it was complete before confessing his sin.
Maintain a Biblical decision making process for your life and constantly examine your life for any sin that should be confessed.
Notes: A- 1 Samuel 16:13; B- Exodus 30:12; C- 1 Chronicles 21:3; D- 2 Samuel 12:13; 24:10, 17; Psalm 41:4, 51:4; 1 Chronicles 21:8;