Wednesday, September 3, 2025

SQL - Query Analytics Basic

 SELECT Nome_Produto,

ROUND(MIN(Valor_Venda), 2) AS Valor_Minimo, ROUND(MAX(Valor_Venda), 2) AS Valor_Maximo, ROUND(AVG(Valor_Venda), 2) AS Valor_Medio, ROUND(SUM(Valor_Venda), 2) AS Valor_Total, COUNT(Valor_Venda) AS Contagem, Ano FROM TB_DSA_VENDAS, TB_DSA_PRODUTOS, TB_DSA_PEDIDOS WHERE TB_DSA_VENDAS.Produto = TB_DSA_PRODUTOS.ID_Produto AND TB_DSA_VENDAS.Pedido = TB_DSA_PEDIDOS.ID_Pedido GROUP BY Produto, Ano ORDER BY Contagem DESC;

Tuesday, March 11, 2025

Power Query - funcao limpa replace texto numero

//fnc_limpa_numeros

(TextValue as nullable text) =>

let

    SafeText = if TextValue = null then "" else TextValue,

    DigitsOnly = Text.Combine(

        List.Select(Text.ToList(SafeText), each Text.Contains("0123456789", _))

    )

in

    DigitsOnly

    

//fnc_limpa_text

(TextValue as nullable text) =>

let

    SafeText = if TextValue = null then "" else TextValue,


    // Tabela com caracteres acentuados e suas substituições

    AccentsList = {

        {"à","a"},{"á","a"},{"â","a"},{"ã","a"},{"ä","a"},

        {"è","e"},{"é","e"},{"ê","e"},{"ë","e"},

        {"ì","i"},{"í","i"},{"î","i"},{"ï","i"},

        {"ò","o"},{"ó","o"},{"ô","o"},{"õ","o"},{"ö","o"},

        {"ù","u"},{"ú","u"},{"û","u"},{"ü","u"},

        {"À","A"},{"Á","A"},{"Â","A"},{"Ã","A"},{"Ä","A"},

        {"È","E"},{"É","E"},{"Ê","E"},{"Ë","E"},

        {"Ì","I"},{"Í","I"},{"Î","I"},{"Ï","I"},

        {"Ò","O"},{"Ó","O"},{"Ô","O"},{"Õ","O"},{"Ö","O"},

        {"Ù","U"},{"Ú","U"},{"Û","U"},{"Ü","U"},

        {"ç","c"},{"Ç","C"},{"ñ","n"},{"Ñ","N"}

    },


    // Primeiro remove os acentos explicitamente

    WithoutAccents = List.Accumulate(

        AccentsList, 

        SafeText, 

        (text, pair) => Text.Replace(text, pair{0}, pair{1})

    ),


    // Remove todos os caracteres não alfabéticos (pontuação, especiais, números)

    CleanedText = Text.Combine(

        List.Select(

            Text.ToList(WithoutAccents), 

            each Text.Contains("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", _)

        ), ""

    )

in

    CleanedText   

Chamada: = Table.TransformColumns(#"Uppercased Text", {{"NAME", fnc_limpa_text}})

Friday, February 28, 2025

Power Query - fnc funcao Date

   #"Changed column type" = Table.TransformColumnTypes(#"Renamed columns2", {{"INÍCIO DO ANO LETIVO", Int64.Type}, {"INÍCIO DO RECESSO", Int64.Type}, {"FIM DO ANO LETIVO", Int64.Type}, {"FIM DO RECESSO", Int64.Type}}),

  #"Lowercased text" = Table.TransformColumns(#"Changed column type", {{"INÍCIO DO ANO LETIVO", each Date.AddDays(DataBase, Number.FromText(Text.From(_))), type date}}),
  #"Lowercased text 1" = Table.TransformColumns(#"Lowercased text", {{"INÍCIO DO RECESSO",  each Date.AddDays(DataBase, Number.FromText(Text.From(_))), type date}}),
  #"Lowercased text 2" = Table.TransformColumns(#"Lowercased text 1", {{"FIM DO ANO LETIVO",  each Date.AddDays(DataBase, Number.FromText(Text.From(_))), type date}}),
  #"Lowercased text 3" = Table.TransformColumns(#"Lowercased text 2", {{"FIM DO RECESSO",  each Date.AddDays(DataBase, Number.FromText(Text.From(_))), type date}})
in
  #"Lowercased text 3"

Friday, April 5, 2024

Power Query - Calculate Between RATE x HOURS

     //Carrega tab Faturamento 

    #"Added Custom" = Table.AddColumn(FAT_Faturamento_Table, "Referencia", each "01_Prio"),

    //Carrega tab Rate 

    Rate_Faturamento_Table = DIM_TaxWallet_csv_DF,


    // Merge entre os datasets com base na referência e data

    Merged_Table = Table.Join(#"Added Custom", "Referencia", Rate_Faturamento_Table, "Referencia"),

    // Ajusta tipos de datas

    #"Changed Type2" = Table.TransformColumnTypes(Merged_Table,{{"DataFinal", type text}, {"DataInicial", type text}}),

    #"Changed Type" = Table.TransformColumnTypes(#"Changed Type2",{{"DataInicial", type date}, {"DataFinal", type date}, {"dt_Aberto", type date}}),

    // Criar validação da Rate Between

    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Valid_DateRate", each if ([dt_Aberto] >= [DataInicial] and [dt_Aberto] <= [DataFinal]) then "Y" else "N"),

    // Considera apenas validação Y 

    #"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each ([Valid_DateRate] = "Y")),

    // Então Calcula Rate x Horas

    #"Added Custom1" = Table.AddColumn(#"Filtered Rows", "VlrCostEstimadoTicket", each [ValorHora] * [VlrEst_Prio]),

Friday, December 8, 2023

Script para executar scripts Google Colab

 script.bat

@echo off

powershell -ExecutionPolicy Bypass -File "D:\script.ps1"


script.ps1

# Defina a URL do link

$url = "https://colab.research.google.com/drive/sdfdsfgghjdghjgh"

# Inicie o Google Chrome

Start-Process "chrome.exe" -ArgumentList $url -PassThru | Wait-Process

# Aguarde um momento para o Chrome abrir completamente

Start-Sleep -Seconds 22

# Envie o atalho de teclado Ctrl+F9

Add-Type -AssemblyName System.Windows.Forms

[System.Windows.Forms.SendKeys]::SendWait("^{F9}")


Thursday, August 3, 2023

Power Query - Valid Is Number

 let

    origem = TabelaExemplo, // Fonte da tabela

    selecionarNumericos = Table.SelectRows(origem, each Value.Is(Value.FromText([ColunaValores]), type number)) // Filtrar apenas valores numéricos

in

    selecionarNumericos


SQL - Query Analytics Basic

  SELECT Nome_Produto, ROUND(MIN(Valor_Venda), 2) AS Valor_Minimo, ROUND(MAX(Valor_Venda), 2) AS Valor_Maximo, ROUND(AV...