I did some analysis of the chorale 'Wie wunderbarlich ist doch diese Strafe' (from Matthew Passion BWV 244 no.46), see below. But how would I analyse the first chord in measure 2? Obviously, it's an E major chord (1st inversion), but what is its function? You could say it's an altered subdominant, IV♯3, but I think such things are very rare in Bach's music. It could be a secondary dominant, but the following chord is F♯65, of which E major is neither the V nor the VII. So, any help?
Nice example! I'll have to remember this one.
The G♯ here is actually a product of voice leading and only a byproduct of functional harmony. Since beat 2 of m. 2 is a V65 chord that necessitates the A♯ leading tone, Bach has chosen to raise the downbeat of m. 2 from a G to a G♯ to prevent the augmented second from G♮ to A♯.
To put it more simply, Bach is just using the melodic minor scale in the bass, and that raised sixth scale degree creates a major IV6 chord.
Also interesting is that this IV6 chord comes after the previous V chord. This is a deceptive progression that's a bit different than the more common V–vi progression. It also seems to break the modern rule against moving from V to IV, but this V–IV6 deceptive motion was very common in the Baroque. Handel did it all the time, too.
One final comment: this chorale may be best understood historically as being in E.
Bach often used modal melodies to write these chorales. Dorian was especially common, and this is why we often see (for instance) chorales written in G with only a one-flat key signature. It's possible this chorale is really in E Dorian, since that "extra" C♯ in the key signature would be the characteristic Dorian scale degree. This would also mean the chorale begins with V65–i, which is maybe a bit more common an opening than V65/iv–iv.