Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
Why does PowerBI in the SQL pull in the data that is not used in the visual.
I ran a profiler and seen that in my calender table which i am only using two elements in the visual in Direct Query it Selects all the underlying data for that table and then performs the calculation.... Would it nmot be better to just reference the values used in the that visual?
Solved! Go to Solution.
Hi @Anonymous,
I got the information before internally:
This is by design. The intermediate select of columns is irrelevant. If the customer looks at the query plan for such a query they’ll see that the query plan is exactly the same whether the intermediate select includes all of the columns or just the two that are used in the outer select. We use a SQL generator and like nearly all SQL generators we often generate queries that look more complicated than a person might author by hand but end up having the same performance because of how SQL query plan compilers work.
Best Regards,
Qiuyun Yu
Hi @Anonymous,
I got the information before internally:
This is by design. The intermediate select of columns is irrelevant. If the customer looks at the query plan for such a query they’ll see that the query plan is exactly the same whether the intermediate select includes all of the columns or just the two that are used in the outer select. We use a SQL generator and like nearly all SQL generators we often generate queries that look more complicated than a person might author by hand but end up having the same performance because of how SQL query plan compilers work.
Best Regards,
Qiuyun Yu
Hi Qiuyun,
I can vouche that a query ran this way compared to writing it by hand was 2 mins + slower.
But understand where you are coming from.
Hi @Anonymous,
I have sent a email to consult this issue internally. Will let you know if I get any feedback.
Best Regards,
Qiuyun Yu
Thanks Qiuyun Yu.
The sql PowerBI generates is
SELECT
TOP (1000001) [t1].[FinWeekofMonth],[t1].[FinMonthName],[t2].[mediatype],[t2].[ttlname],[t2].[sitecode],SUM([t2].[InsertNetCost])
AS [a0]
FROM
(
((
SELECT
insertbk.adnumbr,
insertbk.ttlcode, -- product/publication code
insertbk.dateins, -- date of apperance
case when insertbk.chargfl = 'Y' then ratecard.cpi else 0 end as InsertNetCost, -- net cost of insert
classes.classnm,
titles.mediatype,
titles.ttlname,
titles.sitecode
FROM
SalesWorks.dbo.adtrans
INNER JOIN insertbk ON adtrans.adnumbr = insertbk.adnumbr
INNER JOIN titles ON titles.ttlcode = insertbk.ttlcode
INNER JOIN classes ON insertbk.iadclass = classes.adclass
INNER JOIN ratecard ON ratecard.adnumbr = insertbk.adnumbr AND ratecard.ttlcode = insertbk.ttlcode AND ratecard.instnum = insertbk.instnum
LEFT OUTER JOIN custacct ON custacct.custid = adtrans.custid
WHERE
month(insertbk.dateins) >= MONTH(GETDATE())-2 and month(insertbk.dateins) <= MONTH(GETDATE())+1 and
YEAR(insertbk.dateins) >= YEAR(GETDATE()) and
insertbk.iadclass >= 1 and insertbk.iadclass <= 15000 and -- class number range
ratecard.soldfor = 1 and -- look for what advert was sold for, ratecard or agreed cost (Overide cost)
insertbk.actvflg <> 'M' and -- exclude killed inserts .... NOTE some inserts can be killed but still charged !
insertbk.actvflg <> 'K' -- exclude killed inserts ... NOTE some inserts can be killed but still charged !
) AS [t2]
left outer join
(SELECT
-- Order Header Data
category.category,
adtrans.adnumbr, -- advert URN
userdefs.userfnam,
userdefs.usersnam,
adtrans.adsourc as SourceCode -- advertising source code (renamed from "adoper" as this was misleading adtrans.adoper is correct value)
FROM
SalesWorks.dbo.adtrans
LEFT OUTER JOIN custacct ON custacct.custid = adtrans.custid
INNER JOIN category ON adtrans.adcatgy = category.adcatgy
INNER JOIN userdefs ON adtrans.adsourc = userdefs.adoper
WHERE adtrans.adnumbr in
(select insertbk.adnumbr from insertbk
INNER JOIN titles ON titles.ttlcode = insertbk.ttlcode
INNER JOIN ratecard ON ratecard.adnumbr = insertbk.adnumbr AND ratecard.ttlcode = insertbk.ttlcode AND ratecard.instnum = insertbk.instnum
WHERE
month(insertbk.dateins) >= MONTH(GETDATE())-2 and month(insertbk.dateins) <= MONTH(GETDATE())+1 and
YEAR(insertbk.dateins) >= YEAR(GETDATE()) and
insertbk.iadclass >= 1 and insertbk.iadclass <= 15000 and -- class number range
ratecard.soldfor = 1 and -- look for what advert was sold for, ratecard or agreed cost (Overide cost)
insertbk.actvflg <> 'M' and -- exclude killed inserts .... NOTE some inserts can be killed but still charged !
insertbk.actvflg <> 'K' -- exclude killed inserts ... NOTE some inserts can be killed but still charged !
)) AS [t0] on
(
[t2].[adnumbr] = [t0].[adnumbr]
)
)
left outer join
(
SELECT [Date],
CAST([Fin Year] as BIGINT)
AS [Fin Year],[FinWeekofMonth],[TIMEFRAME],[FinMonthName]
FROM
(
(SELECT [Date]
,[Index]
,[YearID]
,[Fin Year]
,[FinWeek Number]
,[FinMonthID]
,[FinMonthNo]
,[FinYear/Month]
,[FinWeekofMonth]
, CASE WHEN Calendar$.FinMonthName=DATENAME(m,DATEADD(m,0,GETDATE())) THEN 'This Month' WHEN Calendar$.FinMonthName=DATENAME(m,DATEADD(m,-1,GETDATE())) THEN 'Last Month' WHEN Calendar$.FinMonthName=DATENAME(m,DATEADD(m,1,GETDATE())) THEN 'Next Month' end as "TIMEFRAME"
, CASE WHEN Calendar$.FinMonthName=DATENAME(m,DATEADD(m,0,GETDATE())) THEN '1' WHEN Calendar$.FinMonthName=DATENAME(m,DATEADD(m,-1,GETDATE())) THEN '2' WHEN Calendar$.FinMonthName=DATENAME(m,DATEADD(m,1,GETDATE())) THEN '3' end as "TIMEorder"
,[FinMonthName]
FROM [Salesworks].[dbo].[Calendar$] WHERE [Calendar$].[Date] IS NOT NULL and YEAR([Calendar$].[Date]) >= '2016')
)
AS [t1]
)
AS [t1] on
(
[t2].[dateins] = [t1].[Date]
)
)
WHERE
(
(
(
[t0].[category] = 'Recruitment'
)
AND
(
[t1].[Fin Year] = 2017
)
)
AND
(
[t1].[TIMEFRAME] = 'Next Month'
)
)
GROUP BY [t1].[FinWeekofMonth],[t1].[FinMonthName],[t2].[mediatype],[t2].[ttlname],[t2].[sitecode]
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.