Prime Minister Indira Gandhi's Congress-I Party has failed to make gains in two northern Indian states and was soundly trounced in Communist-controlled West Bengal in state legislative elections that are viewed here as midterm tests of her popularity.

Gandhi, 64, spent the first two weeks of the month crisscrossing the states through the heat and dust of India's summer to boost her party's chances, an indication of the seriousness with which she took these elections.

Even so, the national effect of the balloting Wednesday is largely psychological. Results continued to trickle in tonight.

The Congress-I (for Indira) Party's only clear win came as the head of an 11-party coalition that narrowly defeated a Communist-led grouping of nine parties in the traditionally Marxist, southern Indian state of Kerala.

Otherwise, the Gandhi forces failed to make major inroads against the entrenched Communist government of West Bengal, although Congress-I candidates won five of nine seats in its capital of Calcutta. They also lagged behind in the north Indian states of Haryana and Himachal Pradesh, where a Gandhi aide said today the prime minister had hoped to do much better. Her party had held power in both of them.

The election also marked the debut in an overall campaigning role of Gandhi's son Rajiv, 37, a freshman member of Parliament who is being groomed as the political heir to the Nehru-Gandhi dynasty that has ruled India for most of its 34 years as an independent democracy. Political pundits withheld judgment tonight on his political skills, although the lack of a clearcut Congress-I victory is expected to encourage his opponents within the party, especially Manika Gandhi, the 25-year-old widow of his younger brother Sanjay.

The Congress-I coalition win in Kerala, which had the world's first freely elected Communist government in 1957, buoyed Gandhi's followers. But their hold on the coalition was not firm, and they only defeated the Communist-led front by 14 votes in a 140-member legislature.

With about half the 294 seats decided in West Bengal, the Communist Party group had won 110 while Gandhi's Congress-I had 32. Its showing in Calcutta, however, indicated growing support for Gandhi in the urban area, where years of almost constant power cuts were believed to have worked against the Communist government.

Haryana and Himachal Pradesh remained cliffhangers tonight. In Haryana, a middle-of-the-road opposition coalition led Gandhi's party by one seat. Eleven independents--most of them defectors from Gandhi's party--appeared to hold the balance of power in the state assembly.

With about two-thirds of the seats decided in Himachal Pradesh, Congress-I lagged 20 to 23 behind the Bharatiya Janata Party, considered the strongest noncommunist opposition to Gandhi in the country.

In one of the few by-elections for the national legislature, maverick labor leader Datta Samant, who is running a four-month-old textile strike in Bombay, was soundly trounced. He finished third behind the Bharatiya Janata winner and Congress-I candidate in a race that may thwart his attempts to organize workers in the country.