Parameter & Power Query manipulation needed for SQL output

manp123

New Member
Joined
Apr 20, 2016
Messages
14
Office Version
  1. 2013
Long story short:
I'm using parameter dates (From & To) in m query per "mock" code below

Power Query:
let
    Source = Sql.Database("azeusvmsql03", "GreatLake", [Query="SELECT dim.Calendar.FiscalYear, dim.Calendar.FiscalMonthNumber, dim.Calendar.FiscalQuarter, dim.LocationLatest_v.StoreNumber, dim.Calendar.FiscalYearWeek, SUM(fact.StockChange.NetQuantity) AS Shipments, 
                  dim.Calendar.CalendarDate AS TransactionDate
FROM     fact.StockChange INNER JOIN
                  dim.StockChangeDetail ON fact.StockChange.StockChangeDetailKey = dim.StockChangeDetail.StockChangeDetailKey INNER JOIN
                  dim.Calendar ON fact.StockChange.CalendarKey = dim.Calendar.CalendarKey INNER JOIN
                  dim.LocationLatest_v ON fact.StockChange.LocationLatestKey = dim.LocationLatest_v.LocationLatestKey
GROUP BY dim.StockChangeDetail.TransactionTypeCode, dim.Calendar.CalendarDate, dim.LocationLatest_v.StoreNumber, dim.Calendar.FiscalYear, dim.Calendar.FiscalMonthNumber, dim.Calendar.FiscalQuarter, 
                  dim.Calendar.FiscalYearWeek
HAVING (dim.StockChangeDetail.TransactionTypeCode = 8) AND (dim.Calendar.CalendarDate = CONVERT(DATETIME, '2022-02-07 00:00:00', 102))"]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each [TransactionDate]),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Custom", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each ([Custom] >= InputVariableFrom) and ([Custom] <= InputVariableTo) or ([Custom] >= InputVariableFrom2) and ([Custom] <= InputVariableTo2)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"})
in
    #"Removed Columns"

I want to get rid of filter "
Power Query:
(dim.Calendar.CalendarDate = CONVERT(DATETIME, '2022-02-07 00:00:00', 102))
" and instead use "
Power Query:
([Custom] >= InputVariableFrom) and ([Custom] <= InputVariableTo)
"

It is crucial for to have parameters but the date load hangs because of the amount of rows. Is there anyway I can pass my parameters onto SQL to ensure I only get lines per my dynamic parameter?

BTW I have only started using SQL & M Query so if someone can manipulate the code and post in answer and I will then dissect it for my own learning that would be great
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,214,515
Messages
6,119,972
Members
448,933
Latest member
Bluedbw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top