It's unclear but probably not until he saw it
The balrog of Moria was awakened in TA 1980, that is, more than 1,000 years before the Fellowship entered Moria in TA 3019. It killed King Durin VI and earned its nickname: Durin's Bane. It also killed King Nain I the following year and many other dwarves before they fled.
The existence of Durin's Bane prevented the dwarves from reoccupying Moria after the Battle of Azanulbizar at the end of the War of the Dwarves and Orcs in TA 2799. After the Pyrrhic victory Thraín, son of Thrór and father of Thorin Oakenshield, tried to re-enter Moria. But Dáin said:
You are the father of our Folk, and we have bled for you, and will again. But we will not enter Khazad-dûm. You will not enter Khazad-dûm. Only I have looked through the shadow of the Gate. Beyond the shadow it waits for you still: Durin’s Bane. The world must change and some other power than ours must come before Durin’s Folk walk again in Moria. (RotK, Appendix A)
At this point, some (at least) of the dwarves knew of the existence of Durin's Bane. This makes Balin's attempted re-colonisation in TA 2989 seem recklessly foolhardy, however, they had just vanquished a dragon and an army of wolves and orcs so maybe they were just overconfident.
Given all this, why did Gandalf not expect to meet a balrog in Moria?
The only reasonable explanation is that no one had worked out:
Durin's Bane = Balrog
Gimli recognised it as the former, Legolas as the latter.
When he referred to it at the Council of Elrond, Gimli called it "the nameless fear". Later in Lórien, Celeborn said "We long have feared that under Caradhras a terror slept" but did not seem to know the nature of the "terror". Describing his confrontation with it through the door of the Chamber of Mazarbul, Gandalf says, "what it was I cannot guess".
It seems that the dwarves did not know what Durin's Bane was — Durin's folk had not been involved in the wars of the First Age and even if there were refugee dwarfs who had been, that was many generations ago. Presumably, first hand accounts by dwarves who actually saw Durin's Bane would be rare because seeing it and living to talk about it is a neat trick. So the dwarves did not make the connection and neither did anyone else.