Fill Blanks In A Column With Last Non-Blank Value

Input collection: myCities52

CountryCityPopulation
United StatesNew York8600000
Los Angeles4057000
Chicago2679044
CanadaToronto5429000
Montreal3519000
MexicoMexico City8000000


Output collection: mySolution52

CountryCityPopulation
United StatesNew York8600000
United StatesLos Angeles4057000
United StatesChicago2679044
CanadaToronto5429000
CanadaMontreal3519000
MexicoMexico City8000000


Solution code:

//Create a collection
ClearCollect(
    myCities52,
    {Country: "United States", City: "New York", Population: 8600000},
    {Country: Blank(), City: "Los Angeles", Population: 4057000},
    {Country: Blank(), City: "Chicago", Population: 2679044},
    {Country: "Canada", City: "Toronto", Population: 5429000},
    {Country: Blank(), City: "Montreal", Population: 3519000},
    {Country: "Mexico", City: "Mexico City", Population: 8000000}
);

//Fill cells with last non-blank value code
ClearCollect(fillBlanksWith,{Country:""});

ClearCollect(mySolution52,myCities52);
ForAll(
    myCities52,
    If(IsBlank(myCities52[@Country]),
        Patch(
            mySolution52, 
            LookUp(mySolution52,City=myCities52[@City]),
            {Country: First(fillBlanksWith).Country}
        ),
        Patch(
            fillBlanksWith,
            First(fillBlanksWith),
            {Country: myCities52[@Country]}
        )
    )
);