我有一个日期/时间列,格式为“ 13.10.2020 06:08:43”,我需要从当前时间计算“年龄”。输出应类似于给定示例:“ 4h”,因为其10:08 atm-日期/时间列为4h之前。我需要使用M语言才能在Visual Studio 2019中使用它。
我用过:
let
Source = Sql.Database("xxxx", "xxxxx", [Query="SELECT#(lf)#(tab)storeid as 'Shop'#(lf)#(tab), concat('SCO', posnr) as POS#(lf)#(tab), concat(datediff(hour,[LastTransactionDate]#(lf)#(tab), CURRENT_TIMESTAMP),' h') as 'Age'#(lf)#(tab), POSIPaddress as 'IP'#(lf)#(tab),[PosNr]#(lf) ,[AdapterPosOrGroupId]#(lf) ,[UpdatedOn]#(lf) ,[LastTransactionDate]#(lf) ,[LastStartDate]#(lf) ,[Open]#(lf) ,[Locked]#(lf) ,[CashDisabled]#(lf) ,[IsCashEnabled]#(lf) ,[CashDevicesTraficLight]#(lf) ,[POSIPAddress]#(lf) ,[ScoPosServiceVersion]#(lf) ,[WinScoVersion]#(lf) ,[StoreType]#(lf)FROM [LaneEventDatabase ].[dbo].[POS.LaneCurrentState]"]),
#"Added Conditional Column" = Table.AddColumn(Source, "Custom", each if [CashDevicesTraficLight] = "green" then 1 else if [CashDevicesTraficLight] = "yellow" then 2 else if [CashDevicesTraficLight] = "red" then 3 else 4),
#"Changed Type" = Table.TransformColumnTypes(#"Added Conditional Column",{{"Custom", type number}})
in
#"Changed Type"
效果很好,但是Visual Studio不喜欢处理源的方式,而在部署时却给我错误:
Failed to save modifications to the server. Error returned: 'An M partition uses a data function which results in access to a data source different from those defined in the model.
'.