Power BI 图表上的重叠周期值摘要
Overlapping periods value summary on chart in Power BI
我不知道我在寻找什么,也许这就是我无法在线找到解决方案的原因。
只是想在带有时间轴的简单图表上显示数据。
我的数据示例:
ID
StartTime
EndTime
Quantity
1
11:00:00
12:00:00
10
2
11:30:00
12:20:00
10
3
12:00:00
13:00:00
10
4
13:40:00
14:00:00
10
5
13:50:00
15:00:00
10
现在我想在图表上显示:
Axis
Value on Chart
11:00:00
10
11:15:00
10
11:30:00
20
11:45:00
20
12:00:00
20
12:15:00
20
12:30:00
10
12:45:00
10
...
...
因此重叠周期值应在图表上显示为总和。
轴间隔15分钟只是举例,如果需要可以固定为10或15分钟。
在我的示例中,我将您问题中的数据放入 table(插入 > table)并将其命名为 tblData。
轴数据在 table tblAxis 中,使用检查开始和结束时间的 SUMIFS 公式计算数量。
=SUMIFS(tblData[Quantity];tblData[StartTime];"<=" & [@Axis];tblData[EndTime];">" & [@Axis])
定义一个新的 table 对应于您显示的 Axis 列,然后编写一个度量以用于沿着这些行的值:
ChartValue =
VAR CurrTime = SELECTEDVALUE ( NewTable[Axis] )
RETURN
CALCULATE (
SUM ( Data[Amount] ),
Data[StartTime] <= CurrTime,
Data[EndTime] >= CurrTime
)
在 PQ M 代码中你可以:
- 创建从最早开始到最晚结束的所有 15 分钟 bin 的列表
- 为每一行创建一个包含 15 分钟 bin 的列表 Start..End
- 将两者合并
JoinType.FullOuter
- 按 bin 分组,return 每个间隔的 Sum 和 Sort
来源
M代码
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0tDIwACIQ0wjBNFCK1YlWMoIoMEYoMEJVYIymzRjdBBOIqAlM1ARdgSlEgSlM1BRFQSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, StartTime = _t, EndTime = _t, Quantity = _t]),
//set data types
#"Changed Type" = Table.TransformColumnTypes(Source,{
{"ID", Int64.Type}, {"StartTime", type time}, {"EndTime", type time}, {"Quantity", Int64.Type}}),
//create List of all 15 minute intervals from earliest Start time to latest End time
quarterHours = List.Times(
List.Min(#"Changed Type"[StartTime]),
Duration.TotalMinutes(
List.Max(#"Changed Type"[EndTime]) - List.Min(#"Changed Type"[StartTime]))/15,#duration(0,0,15,0)),
//compute a List of 15 minute bins for each row
// where Start Time is rounded down to the 15 minute interval; and End Time is rounded up to the 15 minute interval
#"Added Custom" = Table.AddColumn(#"Changed Type", "Time Bin",
each List.Transform(
{Number.RoundDown(Number.From([StartTime])*96,0)..Number.RoundUp(Number.From([EndTime])*96,0)-1},
each _/96)),
//expand the Time Bin list to one entry per 15 minute interval
//and set the data type
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Time Bin"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Time Bin", type time}}),
//Join the column that has ALL of the 15 minute bins (so as to account for those intervals with no entries
addAllTimes = Table.Join(#"Changed Type1","Time Bin",
Table.FromColumns({quarterHours},type table[Bin=Time.Type]),"Bin",JoinKind.FullOuter),
//Group by Bin and Sort by time
#"Grouped Rows" = Table.Group(addAllTimes, {"Bin"}, {{"Quantity", each List.Sum([Quantity]), type nullable number}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Bin", Order.Ascending}})
in
#"Sorted Rows"
结果
谢谢你们。
两种解决方案都有效!!
但是由于我的知识有限,所以使用ike解决方案对我来说更容易。
我不知道我在寻找什么,也许这就是我无法在线找到解决方案的原因。
只是想在带有时间轴的简单图表上显示数据。
我的数据示例:
ID | StartTime | EndTime | Quantity |
---|---|---|---|
1 | 11:00:00 | 12:00:00 | 10 |
2 | 11:30:00 | 12:20:00 | 10 |
3 | 12:00:00 | 13:00:00 | 10 |
4 | 13:40:00 | 14:00:00 | 10 |
5 | 13:50:00 | 15:00:00 | 10 |
现在我想在图表上显示:
Axis | Value on Chart |
---|---|
11:00:00 | 10 |
11:15:00 | 10 |
11:30:00 | 20 |
11:45:00 | 20 |
12:00:00 | 20 |
12:15:00 | 20 |
12:30:00 | 10 |
12:45:00 | 10 |
... | ... |
因此重叠周期值应在图表上显示为总和。 轴间隔15分钟只是举例,如果需要可以固定为10或15分钟。
在我的示例中,我将您问题中的数据放入 table(插入 > table)并将其命名为 tblData。
轴数据在 table tblAxis 中,使用检查开始和结束时间的 SUMIFS 公式计算数量。
=SUMIFS(tblData[Quantity];tblData[StartTime];"<=" & [@Axis];tblData[EndTime];">" & [@Axis])
定义一个新的 table 对应于您显示的 Axis 列,然后编写一个度量以用于沿着这些行的值:
ChartValue =
VAR CurrTime = SELECTEDVALUE ( NewTable[Axis] )
RETURN
CALCULATE (
SUM ( Data[Amount] ),
Data[StartTime] <= CurrTime,
Data[EndTime] >= CurrTime
)
在 PQ M 代码中你可以:
- 创建从最早开始到最晚结束的所有 15 分钟 bin 的列表
- 为每一行创建一个包含 15 分钟 bin 的列表 Start..End
- 将两者合并
JoinType.FullOuter
- 按 bin 分组,return 每个间隔的 Sum 和 Sort
来源
M代码
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI0tDIwACIQ0wjBNFCK1YlWMoIoMEYoMEJVYIymzRjdBBOIqAlM1ARdgSlEgSlM1BRFQSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, StartTime = _t, EndTime = _t, Quantity = _t]),
//set data types
#"Changed Type" = Table.TransformColumnTypes(Source,{
{"ID", Int64.Type}, {"StartTime", type time}, {"EndTime", type time}, {"Quantity", Int64.Type}}),
//create List of all 15 minute intervals from earliest Start time to latest End time
quarterHours = List.Times(
List.Min(#"Changed Type"[StartTime]),
Duration.TotalMinutes(
List.Max(#"Changed Type"[EndTime]) - List.Min(#"Changed Type"[StartTime]))/15,#duration(0,0,15,0)),
//compute a List of 15 minute bins for each row
// where Start Time is rounded down to the 15 minute interval; and End Time is rounded up to the 15 minute interval
#"Added Custom" = Table.AddColumn(#"Changed Type", "Time Bin",
each List.Transform(
{Number.RoundDown(Number.From([StartTime])*96,0)..Number.RoundUp(Number.From([EndTime])*96,0)-1},
each _/96)),
//expand the Time Bin list to one entry per 15 minute interval
//and set the data type
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Time Bin"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Time Bin", type time}}),
//Join the column that has ALL of the 15 minute bins (so as to account for those intervals with no entries
addAllTimes = Table.Join(#"Changed Type1","Time Bin",
Table.FromColumns({quarterHours},type table[Bin=Time.Type]),"Bin",JoinKind.FullOuter),
//Group by Bin and Sort by time
#"Grouped Rows" = Table.Group(addAllTimes, {"Bin"}, {{"Quantity", each List.Sum([Quantity]), type nullable number}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Bin", Order.Ascending}})
in
#"Sorted Rows"
结果
谢谢你们。
两种解决方案都有效!!
但是由于我的知识有限,所以使用ike解决方案对我来说更容易。