Forum Discussion
Anonymous
8 years agoNot applicable
Store old data upon refresh?
So I have a historical table that has data from years past, but then I have another table that has a live connection to download the latest daily data. How can I structure my query to append the...
sxt173
7 years agoAdvocate II
danielpcamara but how are you automatically refreshing your data model in Excel? Your solution works in Excel if you manually refresh. But let's say you want this to happen automatically or you want to use the data in Power BI. Then you are stuck with whatever was last manually refreshed.
danielpcamara
7 years agoResolver I
Yes and no.
uglier part comes now:
I create a Macro on VBA to refresh my workbook always that it is opened. something like this:
Private Sub Workbook_Open()
Sheets("Consulta").Select
Application.Goto Reference:="Atualizado" 'Name of Table to Query
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Application.Goto Reference:="Atualizado" 'Name of Table to Query
Selection.Copy
Application.Goto Reference:="Histórico" 'Name of the Table to save
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ShtSobre.Activate
ThisWorkbook.Save
Application.Quit
End SubTo Reference, your Query will need to merge your history with the new Query, like this:
History:
let
Fonte = Excel.CurrentWorkbook(){[Name="Histórico"]}[Content],
#"Tipo Alterado" = Table.TransformColumnTypes(Fonte,{{"Aplic", Int64.Type}, {"Data", type date}, {"Valor", type number}})
in
#"Tipo Alterado"All Updated:
let
{your code}
#"Consulta Acrescentada" = Table.Combine({ PREVIOUS STEP, Histórico}),
#"Duplicatas Removidas" = Table.Distinct(#"Consulta Acrescentada", { YOUR PKs })
in
#"Duplicatas Removidas"And at last, You can config a Batch or config your OS to open the workbook at a specific time. Something like this:
Be aware this will not work for databases that has a lot of rows, because the Excel limit of rows.