To factor $ x^2-ax+xy-ay $ we can use factoring by grouping.
Group $ \color{blue}{ x^2 }$ with $ \color{blue}{ -ax }$ and $ \color{red}{ xy }$ with $ \color{red}{ -ay }$ then factor each group.
$$ \begin{aligned} x^2-ax+xy-ay &= ( \color{blue}{ x^2-ax } ) + ( \color{red}{ xy-ay }) = \\ &= \color{blue}{ x( x-a )} + \color{red}{ y( x-a ) } = \\ &= (x+y)(x-a) \end{aligned} $$