Forum Discussion
AlekseiDiazPUCP
3 years agoRegular Visitor
Using SQL Statement in advance option for sql databse connector
Hello eveyone I am using this connecction options. The ip address and database name are not the real ones. but the problem I got is for the sql query when I try to filter based on a string column...
AlekseiDiazPUCP
3 years agoRegular Visitor
Hello sir
I might have found the source of my problems within this article
https://learn.microsoft.com/en-us/power-query/native-query-folding
anyways I will drop my code
let
Origen = Sql.Database("000.1.8.00", "database", [CommandTimeout=#duration(0, 6, 0, 0)]),
dbo_REPORTE_VENTA_COMERCIAL = Origen{[Schema="dbo",Item="REPORTE_VENTA_COMERCIAL"]}[Data],
#"Filas >=2023 filtradas" = Table.SelectRows(dbo_REPORTE_VENTA_COMERCIAL, each [AÑO_VIAJE] >= 2023),
#"fecha de viaje agregada" = Table.AddColumn(#"Filas >=2023 filtradas", "FECHA_VIAJE", each #date([AÑO_VIAJE],[MES_VIAJE],[DIA_VIAJE])),
#"fecha de venta agregada" = Table.AddColumn(#"fecha de viaje agregada", "FECHA_VENTA", each #date([AÑO_VENTA],[MES_VENTA],[DIA_VENTA])),
#"fecha de viaje emision agregada" = Table.AddColumn(#"fecha de venta agregada", "FECHA_VIAJE_EMISION", each #date([AÑO_VIAJE_EMISION],[MES_VIAJE_EMISION],[DIA_VIAJE_EMISION])),
#"Errores reemplazados" = Table.ReplaceErrorValues(#"fecha de viaje emision agregada", {{"FECHA_VIAJE_EMISION", null}}),
#"Tipo cambiado con configuración regional" = Table.TransformColumnTypes(#"Errores reemplazados", {{"FECHA_VIAJE", type date}, {"FECHA_VENTA", type date}, {"FECHA_VIAJE_EMISION", type date}}, "es-PE"),
#"Columna condicional agregada" = Table.AddColumn(#"Tipo cambiado con configuración regional", "ETAPA_VIDA_VIAJERO", each if [NUM_PASAJERO_EDAD] = null then "Sin data de edad del viajero" else if [NUM_PASAJERO_EDAD] <= 12 then "Infante (0 a 12 años)" else if [NUM_PASAJERO_EDAD] <= 18 then "Adolescente (13 a 18 años)" else if [NUM_PASAJERO_EDAD] <= 25 then "Joven (19 a 25 años)" else if [NUM_PASAJERO_EDAD] <= 40 then "Adulto joven (26 a 40 años)" else if [NUM_PASAJERO_EDAD] <= 50 then "Adulto intermedio (41 a 50 años)" else if [NUM_PASAJERO_EDAD] <= 60 then "Adulto tardío (51 a 60 años)" else if [NUM_PASAJERO_EDAD] >= 61 then "Senior (61 años a más)" else null),
#"Columna condicional agregada1" = Table.AddColumn(#"Columna condicional agregada", "Orden_Etapa_vida_viajero", each if [ETAPA_VIDA_VIAJERO] = "Infante (0 a 12 años)" then 1 else if [ETAPA_VIDA_VIAJERO] = "Adolescente (13 a 18 años)" then 2 else if [ETAPA_VIDA_VIAJERO] = "Joven (19 a 25 años)" then 3 else if [ETAPA_VIDA_VIAJERO] = "Adulto joven (26 a 40 años)" then 4 else if [ETAPA_VIDA_VIAJERO] = "Adulto intermedio (41 a 50 años)" then 5 else if [ETAPA_VIDA_VIAJERO] = "Adulto tardío (51 a 60 años)" then 6 else if [ETAPA_VIDA_VIAJERO] = "Senior (61 años a más)" then 7 else if [ETAPA_VIDA_VIAJERO] = "Sin data de edad del viajero" then 8 else null),
#"Valor reemplazado" = Table.ReplaceValue(#"Columna condicional agregada1",null,"Sin data de género del viajero",Replacer.ReplaceValue,{"NOM_GENERO"})
in
#"Valor reemplazado"BA_Pete
3 years agoSuper User
The only thing I can see that might affect the inital enabling of query folding is the command timeout argument. Try either removing that argument from the code directly so it looks like the below or, if that doesn't work, remake the connection to the server/db but don't specify any timeout or SQL Statement.
let
Origen = Sql.Database("000.1.8.00", "database"),
dbo_REPORTE_VENTA_COMERCIAL = Origen{[Schema="dbo",Item="REPORTE_VENTA_COMERCIAL"]}[Data],
...
in
...
I've not checked whether any of your subsequent steps will break query folding, the main thing is to just get the #"Filas >=2023 filtradas" step folding, then you know it's working.
Pete