Tyger Guzman Profolio
  • About
  • Resume
    Tyger Guzman

    Tyger Guzman

    Data Analysis with Call Center Background

    • San Antonio, Tx
    • LinkedIn
    • GitHub
    • Email

    Pq str to sql

    less than 1 minute read

    Str to SQLt
    Problem: 
        Pass an integer to a SQL Query in Excel Power Query. 

    Solution: 
        Create A Table and Define the Name : 
    Parameter
    Value
    DaysBack
    30
    Create a Blank Query and Create a Function 

    (ParameterName as text) =>
    let
    ParamSource = Excel.CurrentWorkbook(){[Name="Parameters"]}[Content],
    ParamRow = Table.SelectRows(ParamSource, each ([Parameter] = ParameterName)),
    Value=
    if Table.IsEmpty(ParamRow)=true
    then null
    else Record.Field(ParamRow{0},"Value")
    in
    Value

    On the Next Query you do you can insert the parameter at the top of the list : 
    let
        DaysBack = fnGetParameter("DaysBack")


    The SQL Query Would Look like: 
    Where datediff(day,  convert(date,CONVERT(DATETIME,CONVERT(CHAR(8),DATEADD(ss,-(al.LoginDuration), al.LogoutDateTime),1)),0),Convert(date,GetDate(),0))  <= ' " & Number.ToText(DaysBack) & " '

    Categories: Excel

    Updated: September 27, 2018

    Share on

    Twitter Facebook Google+ LinkedIn
    Previous Next

    You may also enjoy

    Shpt overtimelist

    less than 1 minute read

    Overtime Sign-Up

    Shpt hidesidenav

    less than 1 minute read

    Hide SideNav

    Shpt downloadfile

    less than 1 minute read

    Download A File

    Shpt cssfile

    1 minute read

    CSS File

    • Follow:
    • Feed
    © 2018 Tyger Guzman. Powered by Jekyll & Minimal Mistakes.