Bamidbar3:40

וַיֹּאמֶר יְהוָה אֶל־מֹשֶׁה פְּקֹד כָּל־בְּכֹר זָכָר לִבְנֵי יִשְׂרָאֵל מִבֶּן־חֹדֶשׁ וָמָעְלָה וְשָׂא אֵת מִסְפַּר שְׁמֹתָם׃

And the Eternal said to Moshe: "Count every firstborn male of the children of Israel from a month old and up, and take the number of their names.

Bamidbar 3:40

וַיֹּאמֶר יְהוָה אֶל־מֹשֶׁה

Bamidbar / Numbers 3:40 · Drash

Bamidbar 3:40

וַיֹּאמֶר יְהוָה אֶל־מֹשֶׁה פְּקֹד כָּל־בְּכֹר זָכָר לִבְנֵי יִשְׂרָאֵל מִבֶּן־חֹדֶשׁ וָמָעְלָה וְשָׂא אֵת מִסְפַּר שְׁמֹתָם׃

And the Eternal said to Moshe: "Count every firstborn male of the children of Israel from a month old and up, and take the number of their names.

Drash דְּרָשׁ

Clean grain is counted

A farmer does not count the rubbish in his shed, but every sack of good grain is on his count. What does it say about you that you are counted?

The midrash tells a parable: a king had many threshing floors, dirty and full of weeds, and he did not count them. But one floor had clean wheat, and that one the king wished to count down to the sack. So the Holy One, blessed is He, does not count the nations, but counts Israel exactly: on the floor are the righteous.

How Midrash Tanchuma (Buber) explain it

Midrash Tanchuma (Buber) Another explanation: "Since you are precious in My eyes, you are honoured."

The Holy One, blessed is He, said: "You are precious in My eyes: to all the nations I gave no count, but to you I gave a count."

A parable. A king of flesh and blood had many threshing floors, and all of them were dirty and full of weeds, and he was not exact about their count. "But on this floor there is good wheat. That is why I want to be exact about its count: how many kor, how many sacks, how many measures."

So too this king, the King over the kings of kings, the Holy One, blessed is He. The threshing floor is Israel, as it says: "My threshing, the son of my floor" (Yeshayahu / Isaiah 21:10), and it says: "Israel is holy to the Eternal, the first of His harvest" (Yirmeyahu / Jeremiah 2:3). The son of His house is Moshe (Moses), as it says: "Not so My servant Moshe: in all My house he is faithful" (Bamidbar / Numbers 12:7).

The Holy One, blessed is He, said to him: "The nations are likened to thorns, as it says: 'And peoples shall be as burnings of lime, as thorns cut down' (Yeshayahu / Isaiah 33:12). So do not be exact about their count. But Israel are righteous, as it says: 'And your people are all righteous' (Yeshayahu / Isaiah 60:21), and it says: 'You are all fair, my love, and there is no blemish in you' (Shir HaShirim / Song of Songs 4:7). So be exact about the count of Israel."

And so Moshe did: he counted them. How many kor, as it says: "Lift the head" (Bamidbar / Numbers 1:2). How many sacks, as it says: "And his host and their counted" (Bamidbar / Numbers 2:4). How many measures, as it says: "Count every firstborn male."

Takeaway

A threshing floor (גֹּרֶן) is a beaten patch of ground where grain is threshed and winnowed. A kor (כּוֹר) is a large measure of grain. Weeds (זוּנִין) grow among the wheat and look like it.
The words "Since you are precious in My eyes" are from the prophet Yeshayahu (Isaiah) (Yeshayahu / Isaiah 43:4). The midrash opens its interpretation with this verse a little earlier.
The three steps of the count go from large to small: first the whole people (Bamidbar / Numbers 1:2), then each banner (Bamidbar / Numbers 2:4), then each firstborn (Bamidbar / Numbers 3:40).
The parable names "the son of his house," but says nothing of him: the text of the parable in the midrash is short.