
561 F.3d 837 (2009)
Grace MUELLER, Appellant,
v.
Michael J. ASTRUE, Commissioner of Social Security, Appellee.
No. 08-1756.
United States Court of Appeals, Eighth Circuit.
Submitted: October 17, 2008.
Filed: April 9, 2009.
*838 Gail Barnett, argued, Des Moines, IA, for appellant.
Gary L. Hayward, AUSA, argued, Des Moines, IA, and Christina Young Mein, Asst. Reg. Counsel, SSA, Kansas City, MO, for appellee.
Before GRUENDER, BEAM, and SHEPHERD, Circuit Judges.
SHEPHERD, Circuit Judge.
Appellant Grace Mueller appeals the district court's judgment, which affirmed the decision of the Commissioner of the Social Security Administration ("Commissioner") denying her application for disabled widow's benefits under Title II of the Social Security Act, 42 U.S.C. § 401 et seq. See 28 U.S.C. § 1291; 42 U.S.C. § 405(g). For the reasons set forth below, we reverse the district court's order affirming the Commissioner's decision and instruct the district court to remand the case to the Commissioner for further proceedings consistent with this opinion.

I.
Mueller filed an application for disabled widow's benefits on January 31, 2003. Her husband died fully insured on January 6, 1990. She never remarried. Mueller claimed that she was unable to work due to limited mobility and chronic pain in her right leg. She injured her right knee in 1962 and underwent knee surgeries in 1963, 1967, and twice in 1974. During her final surgery, doctors removed Mueller's right patella. She still wears a knee brace. Although she initially alleged disability since May 1, 1974, Mueller amended her alleged onset date to September 16, 1996, which corresponded with her fiftieth birthday.
Mueller's educational history shows that she graduated from high school and attended some college. Her past work experience includes part-time employment as a substitute teacher and self-employment as a piano instructor. In 1984, Mueller began substitute teaching. She earned $1,188 in 1984 and $637 in 1985. (Admin. R. at 73.) She did not work from 1986 through 1989. From 1990 to 1995, Mueller taught piano lessons in her home. There is no evidence of her earnings during that period. She did not work from 1996 through 1998. Mueller resumed substitute teaching in 1999. Her salary fluctuated from year to year, but she earned $4,327 in 2002 and $4,779 in 2003. (Id. at 86.) Mueller resumed piano teaching in 2002, and she *839 earned between $400 and $500 per month in 2002 and 2003. (Id. at 191.)
The Commissioner denied Mueller's application both initially and on reconsideration. She then requested a hearing before an Administrative Law Judge ("ALJ"). The ALJ heard testimony from a vocational expert, who opined that, given Mueller's residual functional capacity and past work experience, a person in her position "would [] be able to perform her past relevant work." (Id. at 205, 208-09.) However, the ALJ instructed the expert to "assume" that Mueller's music teaching was "past relevant work" and to "take [Mueller's substitute teaching] into account" even though the ALJ was "not sure it rises to the level of [substantial gainful activity]." (Id. at 204, 208). When Mueller's attorney asked the expert to assume the opposite, that the music and substitute teaching were not substantial gainful activity, the expert testified that a person in Mueller's position "would [not] be capable of any work at a light or higher exertional level[.]" (Id. at 209.)
On April 25, 2006, the ALJ issued a written decision denying Mueller's application. The ALJ applied the five-step sequential evaluation for determining whether claimants are disabled. See 20 C.F.R. § 404.1520(a)(4).[1] At step one, the ALJ concluded that Mueller "ha[d] not engaged in substantial gainful activity at any time relevant to this decision." (Admin. R. at 15.) At step four, however, the ALJ determined that Mueller was "capable of performing past relevant work as a music teacher and substitute teacher." (Id. at 18.) Because Mueller could perform her past relevant work, the ALJ held that she "ha[d] not been under a `disability[ ]' ... from the amended alleged onset date of September 16, 1996[,] through the date of this decision [April 25, 2006]." (Id.) The Social Security Administration Appeals Council denied Mueller's request for review, and the ALJ's decision became the final determination of the Commissioner.
Mueller sought review of the Commissioner's decision by filing the present action in the district court. Mueller claimed that, because the ALJ determined, at step one, that she "ha[d] not engaged in substantial gainful activity at any time relevant to this decision," she did not have any past relevant work. The district court rejected this argument and affirmed the Commissioner's decision. The court found that the phrase, "at any time relevant to this decision," referred only to the time period "since the amended alleged onset *840 date of September 16, 1996." It reasoned that, because "[t]he window for determining past relevant work extends 15 years, [ ] the ALJ was permitted to look at Mueller's activities as far back as 1991 when he issued his order in 2006." Therefore, the court held, when the ALJ found that Mueller's work had not been substantially gainful since September 16, 1996, that finding did not preclude his step-four determination that Mueller could perform past relevant work. Mueller brings this appeal.

II.
"We review de novo the district court's decision upholding the denial of social security benefits." Lowe v. Apfel, 226 F.3d 969, 971 (8th Cir.2000). "When considering whether the ALJ properly denied social security benefits, we determine whether the decision is based on legal error, and whether the findings of fact are supported by substantial evidence in the record as a whole." Id.; see also 42 U.S.C. § 405(g). To qualify for disabled widow's benefits, Mueller must establish, inter alia, that she "ha[d] a disability ... [that] started not later than 7 years after the insured died." 20 C.F.R. § 404.335(c)(1).
As the ALJ properly noted at the outset of his opinion, the date Mueller was last insured for purposes of disabled widow's benefits was January 31, 1997  the end of the 84th month (seventh year) after her husband died. See id. § 404.335(c)(1); (Admin. R. at 12.) Therefore, the ALJ should have used the five-step sequential evaluation to determine whether Mueller was disabled between September 16, 1996, her alleged onset date, and January 31, 1997, her date last insured. See, e.g., Sneed v. Barnhart, 214 Fed.Appx. 883, 884 (11th Cir.2006) (per curiam) (unpublished) (claimant must show she was disabled on or before her date last insured); Morgan v. Sullivan, 945 F.2d 1079, 1080 (9th Cir. 1991) (per curiam) (same), Ivy v. Sullivan, 898 F.2d 1045, 1048 (5th Cir.1990) (same). At steps one and four, however, the ALJ strayed from the retrospective nature of this evaluation.

A. Substantial Gainful Activity (Step One)
The ALJ failed to confine his step-one analysis to the time period from September 16, 1996, to January 31, 1997. Step one requires the Commissioner to decide whether the claimant is engaged in substantial gainful activity.[2] 20 C.F.R. § 404.1520(a)(4)(i). If so, the Commissioner "will find that [the claimant is] not disabled." Id. Mueller was not working at all between September 16, 1996, and January 31, 1997. She quit substitute teaching after 1985 and did not resume until 1999. (Admin. R. at 73.) She quit teaching piano lessons after 1995 and did not resume until 2002.(Id.) Nonetheless, the ALJ evaluated whether Mueller's work, performed well after her date last insured, constituted substantial gainful activity:
The record reflects the claimant worked as a part-time substitute school teacher and self-employed piano instructor since the amended alleged onset date of September 16, 1996; however, the work attempts were part-time and seasonal in nature. Therefore, the undersigned finds the work activities did not constitute substantial gainful activity during the pertinent period in this case.
(Id. at 15.) Despite the ALJ's temporally flawed analysis, his ultimate conclusion  that Mueller was not engaged in substantial gainful activity  was correct. Thus, substantial evidence supports the ALJ's *841 step-one determination. See Lowe, 226 F.3d at 971.

B. Past Relevant Work (Step Four)
The ALJ's analysis was also flawed at step four of the sequential evaluation. Step four requires the Commissioner to determine whether the claimant has the residual functional capacity to perform his or her "past relevant work." 20 C.F.R. § 404.1520(a)(4)(iv). If so, the Commissioner "will find that [the claimant is] not disabled." Id. "Past relevant work is work that you have done within the past 15 years, that was substantial gainful activity, and that lasted long enough for you to learn how to do it." Id. § 404.1560(b)(1) (emphasis added). To decide whether Mueller had the residual functional capacity to do "past relevant work" on or before her date last insured, the ALJ should have analyzed whether Mueller's work during the 15-year period ending on January 31, 1997, rose to the level of substantial gainful activity. See id. §§ 404.335(c)(1), 404.1560(b)(1).
The ALJ found that Mueller was "capable of performing past relevant work [both] as a music teacher and substitute teacher." (Admin. R. at 18 (emphasis added).) During the 15-year period ending with her date last insuredJanuary 31, 1982, to January 31, 1997Mueller's only work as a substitute teacher came in 1984 and 1985, when she earned $1,188 and $637, respectively. (Admin. R. at 73.) At step one of the sequential evaluation, the ALJalbeit unnecessarilyconcluded that Mueller's "work[] as a part-time substitute school teacher ... since her amended alleged onset date of September 16, 1996 ... [was] part-time and seasonal in nature ... [and] did not constitute substantial gainful activity. ..." (Id. at 15.) Thus, even in 2002 and 2003, when Mueller earned $4,327 and $4,779 substitute teaching and more than $400 a month teaching piano lessons, the ALJ did not believe her work constituted substantial gainful activity. (See id. at 86, 191.) Given the ALJ's step-one finding and Mueller's minimal earnings in 1984 and 1985, substantial evidence does not support the ALJ's step-four determination that Mueller had past relevant work as a substitute teacher. See Lowe, 226 F.3d at 971.
During the 15-year period ending with her date last insuredJanuary 31, 1982, to January 31, 1997Mueller taught piano lessons from 1990 to 1995. (Admin. R. at 73.) According to one doctor's report, Mueller was "busy ... with her music teaching and [had] about 43 students" in November 1994. (Id. at 136.) However, the record contains no evidence of her earnings during that period, nor is there any discussion in the ALJ's written decision or the hearing transcript about her work as a piano instructor prior to 2002. Instead, the ALJ instructed the vocational expert to "assume" that Mueller's music teaching was past relevant work (id. at 204), but the ALJ never subsequently "analyz[ed] whether it was past relevant work," Cavazos v. Astrue, No. CV-07-3001-CI, 2008 WL 336792, at *7 (E.D.Wash. Feb.5, 2008) (unpublished). "On remand, the ALJ will need to consider and discuss whether [Mueller's music teaching from 1990 to 1995] qualifies as past relevant work, that is, was performed within the past 15 years [from her date last insured], lasted long enough to learn how to do it, and constituted substantial gainful activity." Id.; see also 20 C.F.R. §§ 404.1520(a)(4)(iv), 1560(b)(1).

III.
Accordingly, we reverse the district court's order affirming the Commissioner's decision and instruct the district court to remand the case to the Commissioner for *842 further proceedings consistent with this opinion.
NOTES
[1]  The five-step sequential evaluation in 20 C.F.R. § 404.1520(a)(4) reads:

(i) At the first step, we consider your work activity, if any. If you are doing substantial gainful activity, we will find that you are not disabled.
(ii) At the second step, we consider the medical severity of your impairment(s). If you do not have a severe medically determinable physical or mental impairment that meets the duration requirement in § 404.1509, or a combination of impairments that is severe and meets the duration requirement, we will find that you are not disabled.
(iii) At the third step, we also consider the medical severity of your impairment(s). If you have an impairment(s) that meets or equals one of our listings in appendix 1 of this subpart and meets the duration requirement, we will find that you are disabled.
(iv) At the fourth step, we consider our assessment of your residual functional capacity and your past relevant work. If you can still do your past relevant work, we will find that you are not disabled.
(v) At the fifth and last step, we consider our assessment of your residual functional capacity and your age, education, and work experience to see if you can make an adjustment to other work. If you can make an adjustment to other work, we will find that you are not disabled. If you cannot make an adjustment to other work, we will find that you are disabled.
[2]  To be "substantial," the work must "involve[ ] doing significant physical or mental activities." 20 C.F.R. § 404.1572(a). To be "gainful," the work must be "the kind of work usually done for pay or profit." Id. § 404.1572(b).
