Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi, I've got an SQL query that I'm wanting to add a date parameter to in order to speed up the loading in desktop.
Below is the whole query, I'm wanting to change the first & only date that appears 1/1/2000 with a parameter. I've called my parameter DateParameter and set it up as the below, but I'm not able to get the parameter into the query, if you're able to assist at all would be greatly appreciated
let
Source = Sql.Database("XX.X.XX.XX", "SD_Travel", [Query="declare @TravelFrom DATE = '1/1/2000' #(lf)Create table #tempData ( #(lf)BookId int, #(lf) ItemType varchar(100), #(lf) PrimaryId int, #(lf) SupplierId int, #(lf) Supplier varchar(50), #(lf) CurrencyId int, #(lf) Currency varchar(50), #(lf) CurrencyCode varchar(20), #(lf) CurrencySymbol varchar(10), #(lf) BuyingCost money, #(lf) NetCost money, #(lf) InvoiceAmount money , #(lf) InvoiceAmountGBP money, #(lf) PaidAmount money, #(lf) PaidAmountGBP money, #(lf) FlagApproved bit, #(lf) FlagPaid bit, #(lf) BookExchangeRate decimal(18,4), #(lf) PaymentExchangeRate decimal(18,4), #(lf) AdjustmentAmount money, #(lf) AdjustmentAmountGBP money, #(lf) CostTypeId int, #(lf) TravelDate DATE, #(lf) BusinessUnitId INT #(lf)) #(lf)--Itinerary cost data #(lf)Insert Into #tempData(BookId,ItemType, PrimaryId, SupplierId, Supplier, CurrencyId, Currency, #(lf) CurrencyCode,CurrencySymbol, BuyingCost, NetCost, Invoiceamount, #(lf) InvoiceAmountGBP, PaidAmount, PaidAmountGBP, FlagApproved, FlagPaid,BookExchangeRate,PaymentExchangeRate, #(lf) AdjustmentAmount, AdjustmentAmountGBP,CostTypeId,TravelDate,BusinessUnitId) #(lf)SELECT bs.bookid, 'Itin', CostDetail.CostId, SupplierContactId, Company, CostDetail.CurrencyId, CostDetail.Currency, #(lf) CostDetail.CurrencyCode, CurrencySymbol, NetCost, NetCostGBP, InvoiceAmount, #(lf) InvoiceAmountGBP, PaidAmount, PaidAmountGBP,FlagApproved, FlagPaid, #(lf) BookExchangeRate,CostDetail.PaymentExchangeRate, #(lf) AdjustmentAmount, AdjustmentAmountGBP,1, BS.StartDate, BS.BusinessUnitId #(lf)FROM SD_Travel.dbo.vwSupplierPayments CostDetail WITH(NOLOCK) #(lf) INNER JOIN SD_Travel.dbo.BookSum BS WITH(NOLOCK) ON BS.BookId = CostDetail.BookId #(lf)Where CostDetail.CostId IS NOT NULL #(lf) AND (NetCost<>0 OR CostDetail.InvoiceAmount <> 0) #(lf) AND BS.StartDate >= @TravelFrom #(lf)--Other cost data #(lf)Insert Into #tempData(bookid, ItemType, PrimaryId, SupplierId, Supplier, CurrencyId, Currency, #(lf) CurrencyCode, CurrencySymbol, BuyingCost, NetCost, Invoiceamount, #(lf) InvoiceAmountGBP, PaidAmount, PaidAmountGBP, FlagApproved, FlagPaid,BookExchangeRate,PaymentExchangeRate, #(lf) AdjustmentAmount,AdjustmentAmountGBP,CostTypeId,TravelDate,BusinessUnitId) #(lf)SELECT bs.bookid, SupplimentTitle, OtherCostId as PartyItinId, SupplierContactId, SupplierName, #(lf) CostDetail.CurrencyId, CostDetail.Currency, CostDetail.CurrencyCode,CurrencySymbol, #(lf) NetCost as BuyingCost, NetCostGBP, InvoiceAmount, InvoiceAmountGBP, #(lf) PaidAmount, PaidAmountGBP, FlagApproved, FlagPaid,BookExchangeRate, #(lf) CostDetail.PaymentExchangeRate, #(lf) AdjustmentAmount, AdjustmentAmountGBP,2, BS.StartDate, BS.BusinessUnitId #(lf)FROM SD_Travel.dbo.vwSupplierPaymentOthers CostDetail WITH(NOLOCK) #(lf) INNER JOIN SD_Travel.dbo.BookSum BS WITH(NOLOCK) ON BS.BookId = CostDetail.BookId #(lf)Where SuppTypeId In (1,5) AND SupplierContactId IS NOT NULL #(lf) AND (NetCost<>0 OR CostDetail.InvoiceAmount <>0) #(lf) and SuppGroupId<>3 #(lf) AND BS.StartDate >= @TravelFrom #(lf)--Experience Cost #(lf)Insert Into #tempData(Bookid,ItemType, PrimaryId, SupplierId, Supplier, CurrencyId, Currency, #(lf) CurrencyCode, CurrencySymbol, BuyingCost, NetCost, Invoiceamount, #(lf) InvoiceAmountGBP, PaidAmount, PaidAmountGBP, FlagApproved, FlagPaid,BookExchangeRate,PaymentExchangeRate, #(lf) AdjustmentAmount,AdjustmentAmountGBP,CostTypeId,TravelDate,BusinessUnitId) #(lf)SELECT bs.bookid, 'Experience', OtherCostId as PartyItinId, SupplierContactId, SupplierName, #(lf) CostDetail.CurrencyId, CostDetail.Currency, CostDetail.CurrencyCode,CurrencySymbol, #(lf) NetCost as BuyingCost, NetCostGBP, InvoiceAmount, InvoiceAmountGBP, #(lf) PaidAmount, PaidAmountGBP, FlagApproved, CostDetail.FlagPaid,BookExchangeRate, #(lf) CostDetail.PaymentExchangeRate, #(lf) AdjustmentAmount, AdjustmentAmountGBP,2, BS.StartDate, BS.BusinessUnitId #(lf)FROM SD_Travel.dbo.vwSupplierPaymentOthers CostDetail WITH(NOLOCK) #(lf) INNER JOIN SD_Travel.dbo.BookSum BS WITH(NOLOCK) ON BS.BookId = CostDetail.BookId #(lf) Inner Join SD_Travel.dbo.BookItineraryDetail ItinDetail On ItinDetail.ItinDetailId = CostDetail.DetailId and ItinDetail.ItemType='Experience' #(lf)Where SuppTypeId In (7) AND SupplierContactId IS NOT NULL #(lf) AND (NetCost<>0 OR CostDetail.InvoiceAmount <>0) #(lf) and SuppGroupId<>3 #(lf) AND BS.StartDate >= @TravelFrom #(lf)--Cancellation charges #(lf)Insert Into #tempData(Bookid, ItemType, PrimaryId, SupplierId, Supplier, CurrencyId, Currency, #(lf) CurrencyCode, CurrencySymbol, BuyingCost, NetCost, Invoiceamount, #(lf) InvoiceAmountGBP, PaidAmount, PaidAmountGBP, FlagApproved, FlagPaid,BookExchangeRate,PaymentExchangeRate, #(lf) AdjustmentAmount,AdjustmentAmountGBP,CostTypeId,TravelDate,BusinessUnitId) #(lf)SELECT bs.bookid, 'Supplement', OtherCostId as PartyItinId, SupplierContactId, SupplierName, #(lf) CostDetail.CurrencyId, CostDetail.Currency, CostDetail.CurrencyCode,CurrencySymbol, #(lf) NetCost as BuyingCost, NetCostGBP, InvoiceAmount, InvoiceAmountGBP, #(lf) PaidAmount, PaidAmountGBP, FlagApproved, CostDetail.FlagPaid,BookExchangeRate, #(lf) CostDetail.PaymentExchangeRate, #(lf) AdjustmentAmount, AdjustmentAmountGBP,2, BS.StartDate, BS.BusinessUnitId #(lf)FROM SD_Travel.dbo.vwSupplierPaymentOthers CostDetail WITH(NOLOCK) #(lf) INNER JOIN SD_Travel.dbo.BookSum BS WITH(NOLOCK) ON BS.BookId = CostDetail.BookId #(lf)Where SupplimentId = 630 AND SupplierContactId IS NOT NULL #(lf) AND BS.StartDate >= @TravelFrom #(lf)Select Distinct Bookid, ItemType,PrimaryId,SupplierId, Supplier, #(lf) BuyingCost Cost, NetCost, IsNull(InvoiceAmount,0) as Invoice, #(lf) IsNull(InvoiceAmountGBP,0) as InvoiceGBP, IsNull(PaidAmount,0) as Paid, IsNull(PaidAmountGBP,0) as PaidGBP, #(lf) BookExchangeRate, PaymentExchangeRate, #(lf) TravelDate, bu.BusinessUnitName,Currency #(lf)From #tempData PaymentSummary #(lf) INNER JOIN LTGMaster.dbo.BusinessUnitMaster bu ON bu.BusinessUnitId = PaymentSummary.BusinessUnitId #(lf)order by TravelDate #(lf)DROP TABLE #tempData #(lf)"]),
Replace
DATE = '1/1/2000' #(lf)Create table
with
DATE = '"&DateParameter&"' #(lf)Create table
--Nate
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
9 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
12 | |
11 | |
9 | |
6 | |
6 |