我有一些原始数据
现在我想写一些DAX,以便可以进行以下操作:
如您所见,我在那里能够得到一个约会。这是我使用的DAX:
Last MT 1 Date =
CALCULATE (
VALUES ( Main_Tanks_Last[Last Date].[Date] ),
FILTER ( Main_Tanks_LAST, [Main Tank 1 ID] = VALUES( Main_Tanks[Tank ID] ) )
)
那么,我怎样才能得到一个列,以便它查看坦克以确定其ID,并将其与主坦克1 ID,主坦克2 ID或主坦克3 ID进行比较并填写日期?而且,如果没有坦克1 2或3,它也不会引发错误。
数据是从SQL Server 2014导入的。
添加的信息
因此原始数据来自此SQL查询:
DECLARE @MT1_ID AS INT, @MT2_ID AS INT, @MT3_ID AS INT
SELECT DISTINCT
IBX_Name AS "IBX",
(SELECT ([Tank_ID]) FROM Tanks WHERE Tanks.fk_IBX_ID = IBXs.IBX_ID AND Tanks.Main_Tank_Index = 1) AS "Main Tank 1 ID",
AST_UST_Level1 AS "Latest Main Tank 1 Level",
(SELECT ([Tank_ID]) FROM Tanks WHERE Tanks.fk_IBX_ID = IBXs.IBX_ID AND Tanks.Main_Tank_Index = 2) AS "Main Tank 2 ID",
AST_UST_Level2 AS "Latest Main Tank 2 Level",
(SELECT ([Tank_ID]) FROM Tanks WHERE Tanks.fk_IBX_ID = IBXs.IBX_ID AND Tanks.Main_Tank_Index = 3) AS "Main Tank 3 ID",
AST_UST_Level3 AS "Latest Main Tank 3 Level",
RunData_Date AS "Last Date"
FROM RunData
INNER JOIN Tanks ON Tanks.fk_GeneratorName_ID = RunData.fk_GeneratorName_ID
INNER JOIN IBXs ON IBXs.IBX_ID = Tanks.fk_IBX_ID
INNER JOIN GeneratorNames ON GeneratorNames.GeneratorName_ID = RunData.fk_GeneratorName_ID
WHERE ([RunData_Date] = (SELECT Max([RunData_Date]) FROM RunData AS T1 WHERE T1.fk_IBX_ID = IBX_ID AND (T1.AST_UST_Level1 > 0 OR T1.AST_UST_Level2 > 0 OR T1.AST_UST_Level3 > 0)))
这实际上是较大数据集的一小部分:
IBX Generator Main Tank 1 ID Latest Main Tank 1 Level Main Tank 2 ID Latest Main Tank 2 Level Main Tank 3 ID Latest Main Tank 3 Level Last Date
---------- -------------------------------------------------- -------------- ------------------------ -------------- ------------------------ -------------- ------------------------ ----------
DC2 DC2-Generator-1 1 16128 2 16192 NULL NULL 2018-11-08
DC2 DC2-Generator-2 1 16128 2 16192 NULL NULL 2018-11-08
DC2 DC2-Generator-3 1 16128 2 16192 NULL NULL 2018-11-08
DC2 DC2-Generator-4 1 16128 2 16192 NULL NULL 2018-11-08
DC2 DC2-Generator-5 1 16128 2 16192 NULL NULL 2018-11-08
DC2 DC2-Generator-6 1 16128 2 16192 NULL NULL 2018-11-08
DC4 DC4-Generator-A 3 25881 4 26007 NULL NULL 2020-03-18
DC4 DC4-Generator-B 3 25881 4 26007 NULL NULL 2020-03-18
DC4 DC4-Generator-C 3 25881 4 26007 NULL NULL 2020-03-18
DC4 DC4-Generator-D 3 25881 4 26007 NULL NULL 2020-03-18
DC4 DC4-Generator-E 3 25881 4 26007 NULL NULL 2020-03-18
DC4 DC4-Generator-R 3 25881 4 26007 NULL NULL 2020-03-18
DC4 DC4-Generator-S 3 25881 4 26007 NULL NULL 2020-03-18
DC5 DC5-Generator-E 12 24079 13 23774 NULL NULL 2020-03-13
DC5 DC5-Generator-R 12 24079 13 23774 NULL NULL 2020-03-13
DC5 DC5-Generator-S 12 24079 13 23774 NULL NULL 2020-03-13
所以我必须使用DISTINCT,这样我才能将其保存到一个日期。