Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

SQL to DAX

Hello, I have the following SQL-Script and want to convert it to DAX.

 

 


SELECT top (1)  abs((i.[MVA_L1_5_MAG01_246]-(lead(i.[MVA_L1_5_MAG01_246],1,0)over(order by i.[Date] desc)))) as' Mischerstange 1',
     abs((i.[MVA_L1_5_MAG01_250]-(lead(i.[MVA_L1_5_MAG01_250],1,0)over(order by i.[Date] desc)))) as' Mischerstange 2',
     abs((i.[MVA_L1_5_MAG01_254]-(lead(i.[MVA_L1_5_MAG01_254],1,0)over(order by i.[Date] desc)))) as' Mischerstange 3',
     abs((i.[MVA_L1_5_MAG01_258]-(lead(i.[MVA_L1_5_MAG01_258],1,0)over(order by i.[Date] desc)))) as' Mischerstange 4',
    (i.[MVA_L1_5_MAG01_246]-(lead(i.[MVA_L1_5_MAG01_246],1,0)over(order by i.[Date] desc)))*100/i.Gesamtverbrauch as 'Verbrauch 1',
    (i.[MVA_L1_5_MAG01_250]-(lead(i.[MVA_L1_5_MAG01_250],1,0)over(order by i.[Date] desc))) *100/i.Gesamtverbrauch as 'Verbrauch 2',
    (i.[MVA_L1_5_MAG01_254]-(lead(i.[MVA_L1_5_MAG01_254],1,0)over(order by i.[Date] desc)))*100/i.Gesamtverbrauch as 'Verbrauch 3',
      (i.[MVA_L1_5_MAG01_258]-(lead(i.[MVA_L1_5_MAG01_258],1,0)over(order by i.[Date] desc)))*100/i.Gesamtverbrauch as 'Verbrauch 4'

  

From(
Select TOP 2 [Date] 
  ,[MVA_L1_5_MAG01_246]
      ,[MVA_L1_5_MAG01_250]

 

 

does anyone have a suggestion how I can convert this script into DAX?
      ,[MVA_L1_5_MAG01_254]
      ,[MVA_L1_5_MAG01_258],
   (([MVA_L1_5_MAG01_246]-(lead([MVA_L1_5_MAG01_246],1,0)over(order by [Date] desc)))+([MVA_L1_5_MAG01_250]-(lead([MVA_L1_5_MAG01_250],1,0)over(order by [Date] desc)))+([MVA_L1_5_MAG01_254]-(lead([MVA_L1_5_MAG01_254],1,0)over(order by [Date] desc)))+([MVA_L1_5_MAG01_258]-(lead([MVA_L1_5_MAG01_258],1,0)over(order by [Date] desc)))) as Gesamtverbrauch

  FROM [MEG_LMSdataLogger].[dbo].[Dashboard_PRW_L1_5]
   where datepart(hh,[Date]-1)=6 and datepart(hh,[Date])=6 AND datepart(minute,[DATE])=00
  order by [Date] desc

  )i