简体   繁体   English

PowerBI中的时间表问题-(用于堆积的条形图)

[英]Time table issue in PowerBI - (for stacked bar chart)

Thank you for your time, in advance! 预先感谢您的宝贵时间!

I am using DirectQuery for SQL. 我正在使用DirectQuery for SQL。 Data cannot be imported because the ddbb is too huge. 由于ddbb太大,因此无法导入数据。 In that main/fact table I have a column "date"-dd/MM/yyyy and a column "time"-HH:MM:SS. 在该主/事实表中,我有一列“日期” -dd / MM / yyyy和一列“时间” -HH:MM:SS。 I have calculated a calendar table for dates and I have tried to calculate a time table using different solutions that I've found on internet with M or DAX. 我已经计算出日期的日历表,并且尝试使用在Internet上使用M或DAX找到的不同解决方案来计算时间表。 But none time table is working properly. 但是没有时间表能正常工作。 For example: filtering by "the hour 8" it would have to highlight all times between 8:00:00 and 8:59:59, but it is not showing me all the data entries in that time range. 例如:按“小时8”过滤,则必须突出显示8:00:00到8:59:59之间的所有时间,但是并不能显示该时间范围内的所有数据条目。

I need to make a piled bar chart/stacked bar chart: X-axis:HOUR Y-axis:number of operations gruped by languages. 我需要制作一个堆积的条形图/堆积的条形图:X轴:HOUR Y轴:受语言限制的操作数。 But for some reason not all the operations are shown in the chart. 但是由于某种原因,并不是所有的操作都在图表中显示。 I believe the calculated time table is not filtering properly the time column from my fact table. 我认为计算出的时间表无法正确过滤我的事实表中的时间列。

PowerBI printscreen PowerBI打印屏幕

Note: I do have the latest version of PowerBI-november. 注意:我确实拥有11月的PowerBI最新版本。

*Note: For the time table I have used these ways: *注意:对于时间表,我使用了以下方法:

  1. in M: 在M中:
 let Source = List.Times(#time(0,0,0) , 1440, #duration(0,0,1,0)), convertToTable = Table.FromList(Source, Splitter.SplitByNothing(), {"DayTime"}, null, ExtraValues.Error), createTimeKey = Table.AddColumn(convertToTable, "TimeKey", each Time.ToText([DayTime], "HHmmss")), hourIndex = Table.AddColumn(createTimeKey, "HourIndex", each Time.Hour([DayTime])), minuteIndex = Table.AddColumn(hourIndex, "MinuteIndex", each Time.Minute([DayTime])), setDataType = Table.TransformColumnTypes(minuteIndex,{{"DayTime", type time}, {"TimeKey", type text}, {"HourIndex", Int64.Type}, {"MinuteIndex", Int64.Type}}) in setDataType 
  1. a more complex M code I've found. 我发现了更复杂的M代码。 I don't need this kind of detail but I did not modify it because I saw it didn't work. 我不需要这种细节,但是我没有修改它,因为我发现它没有用。
 let CreateTimeTable = () as table => let // Similar to our CreateDateTable script, we start with the smallest unit of the dimension, minute // There are a fixed number of minutes in a day, so no need for parameters here // 525,600 minutes divided by 365 days in a year = 1440 minutes in a day. // Who says we never learn from Broadway musicals? MinuteCount = 1440, // Now create a Time type list for a total of 1440 minutes, incrementing one minute at a time Source = List.Times(#time(0, 0, 0),MinuteCount, #duration(0,0,1,0)), // Turn that list into a one column table TableFromList = Table.FromList(Source, Splitter.SplitByNothing()), // Change that table's one column to type Time ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type time}}), // Rename column to Time RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Time"}}), // Start inserting columns for each unit of time to represent in the dimension InsertHour = Table.AddColumn(RenamedColumns, "Hour", each Time.StartOfHour([Time])), InsertMinute = Table.AddColumn(InsertHour, "Minute", each Time.Minute([Time])), ChangedTypeHour = Table.TransformColumnTypes(InsertMinute,{{"Hour", type time}}), // Creating levels in the hierarchy that might be useful for reporting. Omit if not useful to yours InsertQuarterHour = Table.AddColumn(ChangedTypeHour, "Quarter Hour", each if [Minute]<15 then [Hour] else if [Minute] < 30 then Value.Add([Hour],#duration(0,0,15, 0)) else if [Minute] < 45 then Value.Add([Hour],#duration(0,0,30, 0)) else Value.Add([Hour],#duration(0,0,45, 0))), ChangedTypeQtrHr = Table.TransformColumnTypes(InsertQuarterHour,{{"Quarter Hour", type time}}), ReorderedColumns = Table.ReorderColumns(ChangedTypeQtrHr,{"Time", "Hour", "Quarter Hour", "Minute"}), InsertHourNumber = Table.AddColumn(ReorderedColumns, "Hour Number", each Time.Hour([Time])), NextHour = Table.AddColumn(InsertHourNumber, "Next Hour", each Value.Add([Hour],#duration(0,1,0, 0))), NextQuarterHour = Table.AddColumn(NextHour, "Next Quarter Hour", each Value.Add([Quarter Hour],#duration(0,0,15, 0))), InsertPeriod = Table.AddColumn(NextQuarterHour, "Period of Day", each if [Hour Number] >= 0 and [Hour Number] < 4 then "After Midnight" else if [Hour Number] >= 4 and [Hour Number] < 8 then "Early Morning" else if [Hour Number] >= 8 and [Hour Number] < 12 then "Late Morning" else if [Hour Number] >= 12 and [Hour Number] < 16 then "Afternoon" else if [Hour Number] >= 16 and [Hour Number] < 20 then "Evening" else "Late Night"), InsertPeriodSort = Table.AddColumn(InsertPeriod, "PeriodSort", each if [Hour Number] >= 0 and [Hour Number] < 4 then 0 else if [Hour Number] >= 4 and [Hour Number] < 8 then 1 else if [Hour Number] >= 8 and [Hour Number] < 12 then 2 else if [Hour Number] >= 12 and [Hour Number] < 16 then 3 else if [Hour Number] >= 16 and [Hour Number] < 20 then 4 else 5), InsertTimeKey = Table.AddColumn(InsertPeriodSort, "TimeKey", each Time.ToText([Time], "HHmm"), type text) in InsertTimeKey in CreateTimeTable 
  1. Finally a simple DAX column I've created in DAX as simple as this: 最后,我在DAX中创建的一个简单的DAX列就这么简单:
 Hora = VALUES(FactTable[I_Time]) hour = FORMAT(Hora[I_Time]; "HH") hora2 = time(Hora[hour];0;0) 

This is what I want to achieve! 这就是我要实现的! Purpose ! 目的 but for some reason the data is not shown properly. 但由于某些原因,数据无法正确显示。 I am verifying it with SQL queries. 我正在用SQL查询验证它。 And I believe it is because the time table is related as many-many on both sides with the fact table. 我认为这是因为时间表与事实表在许多方面都有很多联系。 The time table doesn't have unique values, but I think it should have just as the calendar table. 时间表没有唯一的值,但我认为它应该与日历表一样。 Now I am using the time table with the DAX code (3). 现在,我将时间表与DAX代码(3)一起使用。

Thanks! 谢谢!

You could simply add an "Hour" calculated column to your fact table, using DAX: 您可以使用DAX简单地将一个“小时”计算列添加到事实表中:

Hour = HOUR ( FactTable[I_Time] )

Or you can generate a TIME table using this M code (a simplified version of #2, in your question), and create a relationship to the Time column of your fact table: 或者,您可以使用此M代码(问题中的#2的简化版本)生成TIME表,并创建与事实表的Time列的关系:

let
    Source = List.Times(#time(0, 0, 0), 1440, #duration(0,0,1,0)),
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), {"Time"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Time", type time}}),
    #"Inserted Hour" = Table.AddColumn(#"Changed Type", "Hour", each Time.Hour([Time]), Int64.Type)
in
    #"Inserted Hour"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM