Help mistake by diff function

Hello Community,
i have a Problem with the diff function in Rstudio. Here are my function and the Output.

a=dbGetQuery(con, 'select extract(year from bestellungen.bestdat) as y, sum((preisVK*menge)) as "Jahresumsatz" from fehlmengen,positionen,kunden,produkte,bestellungen where fehlmengen.tlnr=positionen.tlnr and positionen.bestnr=fehlmengen.bestnr and and positionen.bestnr and produkte.tlnr=positionen.tlnr group by y')
-->a$diff=a$Jahresumsatz - lag(a$Jahresumsatz,1)

It´s doesnt work. I dont get the difference between the years. I am only getting 0 number.

Can anyone help me?


To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.