我试图在powerBi中绘制图表,具有DateTime vs状态, 这是表示数据的更好方式。
目前,我已经尝试了线图和区域图,两者看起来都很糟糕,因为我们的状态值有更多的波动。
以下是数据样本: -
xDate IsHealthy
5/26/2017 12:31 TRUE
5/26/2017 12:41 FALSE
5/26/2017 12:51 FALSE
5/26/2017 13:01 FALSE
5/26/2017 13:11 TRUE
5/26/2017 13:21 FALSE
5/26/2017 13:31 FALSE
5/26/2017 13:41 FALSE
5/26/2017 13:51 TRUE
5/26/2017 14:01 FALSE
5/26/2017 14:11 TRUE
请提供更好的方法,以便从上述数据中获得更多见解
答案 0 :(得分:0)
我会按日期对数据进行分组,然后计数为TRUE和FALSE。假设这是某种“正常运行时间可用性报告”,则根据每天的样本数计算正常运行时间的百分比。
我已将TRUE / FALSE转换为位类型并包含样本数据,以便您可以快速测试。
DECLARE @t TABLE (xDate datetime, IsHealthy bit)
INSERT into @t
VALUES
('5/26/2017 12:31', 1),
('5/26/2017 12:41', 0),
('5/26/2017 12:51', 0),
('5/26/2017 13:01', 0),
('5/26/2017 13:11', 1),
('5/26/2017 13:21', 0),
('5/26/2017 13:31', 0),
('5/26/2017 13:41', 0),
('5/26/2017 13:51', 1),
('5/26/2017 14:01', 0),
('5/26/2017 14:11', 1),
('5/27/2017 12:31', 1),
('5/27/2017 12:41', 1),
('5/27/2017 12:51', 1),
('5/27/2017 13:01', 0),
('5/27/2017 13:11', 1),
('5/27/2017 13:21', 1),
('5/27/2017 13:31', 1),
('5/27/2017 13:41', 0),
('5/27/2017 13:51', 1),
('5/27/2017 14:01', 0)
select distinct
convert(date, xDate) as xDate, IsHealthy
, count(*) over (PARTITION BY convert(date, xDate), IsHealthy) as CountPerState
, count(*) over (PARTITION BY convert(date, xDate)) as TotalCOuntPerDay
, CAST(count(*) over (PARTITION BY convert(date, xDate), IsHealthy) as float) / cast(count(*) over (PARTITION BY convert(date, xDate)) as float) as PercentageOfDay
from @t
这为您提供以下输出
xDate IsHealthy CountPerState TotalCOuntPerDay PercentageOfDay
2017-05-26 0 7 11 0.636363636363636
2017-05-26 1 4 11 0.363636363636364
2017-05-27 0 3 10 0.3
2017-05-27 1 7 10 0.7
现在你有了这个,你可以只绘制PercentageOfDay
IsHealthy=1
行作为一行,或者在堆积列中显示两种状态,具体取决于你喜欢的行。