Lord Dattatreya is supposed to be the form of the trinity gods born on Earth and I saw that he has three faces, each of which resembles one god of the trinity (i.e lord Shiva, lord Vishnu, and lord Brahma).
How was lord Dattatreya born on Earth?
Datta or Dattatreya was the son of the sage Atri, one of the mind-born sons of Brahma, and his wife Anasuya. (He's called Dattatreya because it's Datta + Atreya, the family name of Atri's descendants.) Datta was born together with Soma, the moon god and an incarnation of Brahma, and Durvasa the angry sage who was an incarnation of Shiva. The story is told briefly in the Srimad Bhagavatam:
When Lord Brahmā ordered Atri Muni to create generations after marrying Anasūyā, Atri Muni and his wife went to perform severe austerities in the valley of the mountain known as Ṛkṣa.... He was thinking: "May the Lord of the universe, of whom I have taken shelter, kindly be pleased to offer me a son exactly like Him." While Atri Muni was engaged in these severe austerities, a blazing fire came out of his head by virtue of his breathing exercise, and that fire was seen by the three principal deities of the three worlds. At that time, the three deities approached the hermitage of Atri Muni, accompanied by the denizens of the heavenly planets, such as the celestial beauties, the Gandharvas, the Siddhas, the Vidyādharas and the Nāgas....
The three deities told Atri Muni: "Dear brāhmaṇa, you are perfect in your determination, and therefore as you have decided, so it will happen; it will not happen otherwise.... You will have sons who will represent a partial manifestation of our potency, and because we desire all good fortune for you, those sons will glorify your reputation throughout the world." Thus, while the couple looked on, the three deities Brahmā, Viṣṇu and Maheśvara disappeared from that place after bestowing upon Atri Muni the benediction. Thereafter, from the partial representation of Brahmā, the moon-god was born of them; from the partial representation of Viṣṇu, the great mystic Dattātreya was born; and from the partial representation of Śaṅkara [Lord Śiva], Durvāsā was born.
So, in this telling, the birth of Soma, Dattatreya, and Durvasa are just a reward of Atri's Tapasya.
But there is one more reason for their birth, described in chapter 16 of the the Markandeya Purana. There was once a Brahmana named Kaushika who one night tripped over the sage Mandavya, and so Mandavya was angered and uttered the following curse: "That sinful wretch of a man, by whom, I sorely afflicted and reduced to a miserable plight, have been pushed with feet, shall forsooth be deprived of his life at the sun rise. As soon as he will see the rays of the sun he will meet with destruction." Kaushika's wife was terrified, so she used her magical powers to stop the sun from rising:
Thereupon hearing that dreadful curse, his wife, greatly afflicted, said "The sun shall not rise". Therefore the sun not rising there was a continuous night extending over many days and accordingly the celestials were terrified. They thought "How can this entire universe, shorn of Vedic recitations and those of Vashat, Swaha and Swadha, be saved from being utterly ruined? Without the division of day and night that of months and seasons will cease and from its being destroyed the summer and the winter solstice cannot be known.... There is no lighting of the sacrificial fire and the want of sacrifices is observed." Hearing the words of the celestials assembled there and afraid at the stoppage of sacrifices the god Prajapati (Brahma) said: - "Energy is pacified by energy and asceticism by asceticism; hear, O ye immortals, my words. For the glorification of the chaste wife the sun will not rice; and for his not rising, you and the mortals (are so anxious). If you wish that the sun should rise you should propitiate Atri's wife, the ascetic and devotedly chaste Anusua."
Anasuya was able to convince Kaushika's wife to allow the sun to rise, in exchange for Anasuya using her magical powers to save Kaushika's life. The gods were grateful and offered her a boon:
Anusuya said: - "If the celestials headed by Brahma are propitiated with me and are prepared to give me a boon and If am deemed by you worthy of it, then let Brahma, Vishnu and Maheswara be born as my sons; and may I with my husband acquire Yoga leading to the liberation from miseries." Thereupon, Brahma, Vishnu, Siva, and other gods said "so be it". Then honouring that female ascetic they repaired to their respective habitations.
Thereupon after a long time Brahma's son the divine Atri cast his look upon his own wife Anusua; bathed after her course having all her limbs purified and an excellent form worthy of being coveted by all. Having his mind stricken with desire that ascetic thought in his mind of that one of a blameless person.... The moon, the stay of the life of all creatures, was born as the mind begotten son of the patriarch Atri. Well-pleased the high-souled Vishnu was born from his own body as the best of the twice-born, Dattatreya permeated by the quality of goodness. Incarnating himself Vishnu was born as the second son of Atri known under the name of Dattatreya who sucked the breast of Anusuya.... Then was born Durvasa, a portion of Rudra impregnated with the quality of darkness. Thus Brahma, Vishnu, and Siva were born as her three sons. By virtue of the boon conferred upon her by the celestials Brahma was born at the moon, Vishnu as Dattatreya and Sankara as Durvasa."
So the story in the Markandeya Purana fleshes out the events that led up to the brief story in the Srimad Bhagavatam.
The famous Maharshi Atri was the mind born son of Brahma. The rishi was acknowledged as someone who is on par and even greater than his own father Brahma. He was an exalted sage who went beyond the three modes of existence (trigunas - Sattva, Rajas, Tamas) and the three states of experience (jagruth, sushupti and swapna). He was called Atri because he was a trigunaatheetha (beyond the three states).
He once had a queer desire. He knew that Brahma, Vishnu and Rudra are responsible for creation, sustenance and dissolution of the rahmandas. But there must be someone or something that puts these three (i.e Vishnu, Shiva and Brahma) into action in order to carry on their duties. So, the maharshi went into penance, with the desire to witness the consciousness (paramjyoti) that is the source of the Trimurtis and the entire creation of universe. Anasuya devi, his wife, also performed penance along with him, so that God may shower bountiful grace on mankind. The penance performed by Athri maharshi and his wife went on for thousands of years.
As the fruit of his penance, Athri maharshi witnessed a bright light (paramjyoti) encompassing the entire universe and that light take the form of a 16 year old child. That 16 year child spoke so, "I am the cause of all causes, the source, and the embodiment of trinity (Brahma, Vishnu and Mahehswara). I am pleased with your penance. I shall take birth as your son." This was the first appearance of Dattatreya that occured within the mental vision of the famous Athri maharshi as result of his tiring penance. In reality, the child had no name. He was an embodiment of parabrahma in the saguna form. The indescribable and unqualified Brahman without name and form had given itself to the great sage as a child. And hence was called Datta. Datta literally means "that which is given". Since the brahman has gifted itself as a child to the sage Athri, he was called Dattatreya (Datta + athreya = given to Athri).
Since the trinity - Brahma, Vishnu and Shiva are solely responsible for all activities of existence, anything that comes into being must come via these three only. In reality, the brahman is beyond existence at all levels but even for such all pervading brahman to condense and come into existence within the creation, would imply that he (it) will have to come via Brahma, Vishnu or Shiva only. Hence, the actual birth of Dattatreya took place via the mode of Maha Vishnu and hence the Bhagavatha describes him as the avatar of Maha Vishnu.
Even before Dattatreya was born, the trinity profusely blessed the couple that the three of them would be born to them as children. The incident behind this boon is another well known story from the puranas. The avatar of Dattatreya is very ancient and even predates the Kurma avatar. According to the puranas, it took place hundreds of crores of years back in a different aeon and different age of time. Later on, Lord Dattatreya assumed various forms and avatars such as the Avadhoota and Anagha. This is a brief description of details that lead to the mysterious birth of Dattatreya.