Forum Discussion
lasoe
10 years agoNew Member
Load SQL database tables with different dates automatic
Hi I have a database that generates a new table every day. The name on one of the table is. cdr_ty_20160819_act I would like to make a M script that loads today and the last 30 days. How to d...
v-haibl-msft
Microsoft Employee
10 years ago
Assuming we have some tables in SQL Server like below.
We can paste following Power Query into Advanced Editor.
let
Source = Sql.Databases("HERBERTSQL2016"),
cdr_ty = Source{[Name="cdr_ty"]}[Data],
#"Removed Columns" = Table.RemoveColumns(cdr_ty,{"Schema", "Item", "Kind"}),
#"Expanded Data" = Table.ExpandTableColumn(#"Removed Columns", "Data", {"ID", "Sales"}, {"Data.ID", "Data.Sales"}),
#"Inserted Text Range" = Table.AddColumn(#"Expanded Data", "Text Range", each Text.Middle([Name], 7, 8), type text),
#"Changed Type" = Table.TransformColumnTypes(#"Inserted Text Range",{{"Text Range", type date}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each Date.IsInPreviousNDays([Text Range], 2) or Date.IsInCurrentDay([Text Range]))
in
#"Filtered Rows"We can get one table with following format, which includes data of today and last two days.
Best Regards,
Herbert
Barry_Kelly
9 years agoNew Member
Date.IsInPreviousNDays([Text Range], 2)
Can the day parameter "2" be set by a function or query?