Untitled
unknown
plain_text
5 months ago
2.9 kB
1
Indexable
Original M code: Value.NativeQuery(PostgreSQL.Database(PowerHub_PG_DataSource,PowerHub_PG_DataBase, [CommandTimeout=#duration(0, 3, 0, 0)]), "SELECT #(lf)F1.SD as ""Settlement day"",#(lf)F1.SP as ""Settlement period"",#(lf)F1.PXP as ""PXP-Market Index Price"",#(lf)F2.SBP as ""SBP-System Buy price"",#(lf)F2.SSP as ""SSP-System Sell price"",#(lf)F2.NIV as ""NIV-Net imbalnce Volume ""#(lf)FROM#(lf)(#(lf)SELECT#(lf) SYS_MID.SD,#(lf) SYS_MID.SP,#(lf) AVG(SYS_MID.PXP) As PXP#(lf)FROM#(lf) BOUSER.PP_SYS_MID_SP SYS_MID#(lf)WHERE#(lf) ( (SYS_MID.PROVIDER = case when (SYS_MID.SD < '1-JUL-2004' )then 'UKPXMIDP' when (SYS_MID.SD = '1-JUL-2004' AND SYS_MID.SP < 27 ) then 'UKPXMIDP' else 'APXMIDP' end ) )#(lf) AND #(lf) (#(lf) SYS_MID.LATEST = 1#(lf) AND#(lf) SYS_MID.SD BETWEEN ('" &Date.ToText(Date.AddDays(Start_Date,-1),"dd-MMM-yyyy")& "') AND '" &Date.ToText(End_Date,"dd-MMM-yyyy")& "')#(lf)GROUP BY#(lf)SYS_MID.SD,#(lf)SYS_MID.SP#(lf)#(lf)) F1#(lf)#(lf)FULL OUTER JOIN #(lf)#(lf)(#(lf)SELECT#(lf) SYS_SP.SD,#(lf) SYS_SP.SP,#(lf) AVG(SYS_SP.SBP) As SBP,#(lf) AVG(SYS_SP.SSP) As SSP,#(lf) SUM(SYS_SP.NIV) As NIV#(lf)FROM#(lf) BOUSER.PP_SYS_SP SYS_SP#(lf)WHERE#(lf) SYS_SP.LATEST = 1#(lf) AND#(lf) SYS_SP.SD BETWEEN ('" &Date.ToText(Date.AddDays(Start_Date,-1),"dd-MMM-yyyy")& "') AND '" &Date.ToText(End_Date,"dd-MMM-yyyy")& "' #(lf)GROUP BY#(lf) SYS_SP.SD,#(lf) SYS_SP.SP#(lf) #(lf) ) F2#(lf)#(lf)On F1.SD = F2.SD#(lf)AND F1.SP = F2.SP", null, [EnableFolding=true]) ______________ New M code: PostgreSQL.Database("pgpaas-powerhub-prod-001.postgres.database.azure.com", "ulpodspg001", [CommandTimeout = #duration(0, 1, 40, 0), Query = "select #(lf)sd as ""Settlement day"",#(lf)sp as ""Settlement period"",#(lf)case#(lf)when coalesce(pp_mip.pxp, 0) = 0 then pd_mip.pxp#(lf)else pp_mip.pxp#(lf)end as ""PXP-Market Index Price"",#(lf)pp_sbp_niv.sbp as ""SBP-System Buy price"",#(lf)pp_sbp_niv.ssp as ""SSP-System Sell price"",#(lf)pp_sbp_niv.niv as ""NIV-Net Imbalance Volume""#(lf)from (#(lf)select#(lf)sd,#(lf)sp,#(lf)case when sum(qxp) = 0 then avg(pxp) else sum(pxp * qxp) / sum(qxp) end as pxp #(lf)from bo_user_uniper.pp_sys_mid_sp #(lf)where latest = 1 #(lf)and sd between date '2024-10-12' and date '2024-10-14'#(lf)group by sd, sp#(lf)) pp_mip#(lf)full outer join (#(lf)select #(lf)sd,#(lf)sp,#(lf)avg(sbp) as sbp,#(lf)avg(ssp) as ssp,#(lf)sum(niv) as niv #(lf)from bo_user_uniper.pp_sys_sp #(lf)where latest = 1 #(lf)and sd between date '2024-10-12' and date '2024-10-14'#(lf)group by sd, sp#(lf)) pp_sbp_niv using (sd, sp)#(lf)full outer join (#(lf)select#(lf)sd,#(lf)sp,#(lf)case when sum (volume) = 0 then avg(price) else sum(price * volume) / sum (volume) end pxp#(lf)from bo_user_uniper.pd_mid_sp#(lf)where sd between date '2024-10-12' and date '2024-10-14'#(lf)group by sd, sp#(lf)) pd_mip using (sd, sp)#(lf)order by 1,2"])
Editor is loading...
Leave a Comment