(א) כֵּיצַד מְנַחֲמִין אֶת הָאֲבֵלִים. אַחַר שֶׁקּוֹבְרִין אֶת הַמֵּת מִתְקַבְּצִין הָאֲבֵלִים וְעוֹמְדִין בְּצַד בֵּית הַקְּבָרוֹת. וְכָל הַמְלַוִּין אֶת הַמֵּת עוֹמְדִין סָבִיב לָהֶן שׁוּרָה לִפְנֵי שׁוּרָה. וְאֵין שׁוּרָה פְּחוּתָה מֵעֲשָׂרָה וְאֵין אֲבֵלִים מִן הַמִּנְיָן:
(ב) הָאֲבֵלִים עוֹמְדִין לִשְׂמֹאל הַמְנַחֲמִין וְכָל הַמְנַחֲמִין בָּאִין אֵצֶל הָאֲבֵלִים אֶחָד אֶחָד. וְאוֹמְרִים לָהֶן תְּנֻחֲמוּ מִן הַשָּׁמַיִם. וְאַחַר כָּךְ הוֹלֵךְ הָאָבֵל לְבֵיתוֹ. וְכָל יוֹם וְיוֹם מִשִּׁבְעַת יְמֵי אֲבֵלוּת בָּאִין בְּנֵי אָדָם לְנַחֲמוֹ. בֵּין שֶׁבָּאוּ פָּנִים חֲדָשׁוֹת בֵּין שֶׁלֹּא בָּאוּ:
(1) How is consolation offered to the mourners? When the corpse has been buried, the mourners assemble and remain standing at the border of the cemetery. All who have escorted the deceased stand around them, row after row....
(2) The mourners stand on the left of those who offer consolation, while all the comforters, one by one, approach the mourners and say to them: "May you be comforted by God." Then each mourner goes home. On each of the seven days of mourning, people come to offer him consolation.— —
....my teacher had heard that one should say in the house of the mourner, 'one who dwells here in this house should be comforted'...

שבות יעקב חלק ג סימן צח
גם באתי להודיע חידוש בדין, דאם אותן המתאבלים עמהם מנחמים את אבילם, יאמרו נוסח זה בזה הלשון: המקום ינחם אתכם ואותנו עם שאר אבלי ציון וירושלים
Shvut Yaakov (Rabbi Yakov Reisher, 17th century Prague)
And if these same ones mourning with them are comforting other mourners, they would say this formulation in these words: May God comfort you and ourselves with the mourners of Zion and Jerusalem
It's a Mitzvah to connect the personal pain of our family with the pain of all of Klal Yisrael, and on account of this personal pain we receive meaning and are awakened to Teshuvah and Tikkun. And therefore it is the custom of Ashkenazi Jews, in the time they are comforting mourners, to say: May God comfort you amongst the mourners of Zion and Jerusalem, and add to more sorrow. And Sephardic Jews say 'May your comfort come from Heaven.'
(Rabbi Kalonymos Kalmish Shapira, Sacred Fire: Torah from the Years of Fury 1939-1942, translated by J.H. Worch [Jason Aronson], p.200, Shabbat Nachamu – August 9, 1941)

