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 kunden.id=bestellungen.kunr and bestellungen.id= 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.
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: