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.
I am checking the missing index in my query and if so I skip the row in SQL. But because there are too many checks the query take long time and getting time out error in Power Query. My SQL query
SELECT em.EqmmspvDate,
em.EqmmspvEqmId,
em.EqmmspvValue,
em.Rownumber,
em.t
FROM (
SELECT e.[eqmmspveqmid],
e.[eqmmspvdate],
e.[eqmmspvvalue],
e.t,
e.rownumber,
Lag(e.rownumber, 1, 0)
OVER(
partition BY [eqmmspveqmid]
ORDER BY Min(Datediff(hh, [eqmmspvdate], Getdate())) DESC)
AS
'previuos_rownumber'
FROM (SELECT Row_number()
OVER(
partition BY [eqmmspveqmid]
ORDER BY Min(Datediff(hh, [eqmmspvdate], Getdate())) DESC) AS
Rownumber,
[eqmmspveqmid],
[eqmmspvdate],
Lag(eqmmspvvalue, 1, 0)
OVER(
partition BY [eqmmspveqmid]
ORDER BY Min(Datediff(hh, [eqmmspvdate], Getdate())) DESC) AS
'previuos_kilometerage',
Lead(eqmmspvvalue, 1, 0)
OVER(
partition BY [eqmmspveqmid]
ORDER BY Min(Datediff(hh, [eqmmspvdate], Getdate())) DESC) AS
'next_kilometerage',
Max(Max(eqmmspvvalue))
OVER(
partition BY [eqmmspveqmid]
ORDER BY Min(Datediff(hh, [eqmmspvdate], Getdate())) DESC) AS
'Last_value',
eqmmspvvalue,
[eqmmspvdifference] AS t
FROM [ULTIMO].[dba].[equipmentmspvalue] AS e
WHERE e.eqmmspvrecstatus = 2
AND e.[eqmmspvmspid] = 'DEFAULT'
GROUP BY [eqmmspveqmid],
eqmmspvdate,
[eqmmspvvalue],
[eqmmspvdifference]
) AS e
INNER JOIN #temp AS te
ON te.rownumber = e.rownumber
WHERE e.EqmmspvValue >= e.previuos_kilometerage
GROUP BY e.[eqmmspveqmid],
e.[eqmmspvdate],
e.eqmmspvvalue,
e.t,
e.rownumber) as em
WHERE em.previuos_rownumber + 1 = em.Rownumber
AND previuos_rownumber <> 0
The bottelneck is here :
Lag(e.rownumber, 1, 0)
OVER(
partition BY [eqmmspveqmid]
ORDER BY Min(Datediff(hh, [eqmmspvdate], Getdate())) DESC)
AS
'previuos_rownumber'
Can we do the same in Dax?
regards,
Ezz
@Anonymous , Difficult to tell looking at SQL.
Can you share sample data and sample output in a table format?
But Rank and Earlier can help
For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415
https://powerpivotpro.com/2012/03/the-correct-usage-of-earlier/
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.
User | Count |
---|---|
113 | |
97 | |
80 | |
69 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |