简体   繁体   English

Power BI 时差

[英]Power BI Time Difference

I have a date a user was invited to join an application in the ApplicationUser Table, called DateInvited.我有一个用户被邀请加入 ApplicationUser 表中名为 DateInvited 的应用程序的日期。 I also have a column that stores the time element of the invite(TimeInvited).我还有一列存储邀请(TimeInvited)的时间元素。 I have another table called ApplicationAccessLog that contains a date for the access ( Access Date) and a seperate column for the time id, which is a time key (TimeID) linked to a DimTime table, which then gives tyou the time element.我有另一个名为 ApplicationAccessLog 的表,其中包含访问日期(访问日期)和时间 ID 的单独列,这是链接到 DimTime 表的时间键(TimeID),然后为您提供时间元素。

-ApplicationUser Table ( Not linked to DimTime)

( DateInvitedID ( INT) , DateInvited ( DateTime) , TimeInvited(Time) )

-ApplicationAccessLog ( Linked to DimTime via TimeID)

( AccessDate ( Date) , TimeID ( INT) ) 

-DimTime 

TimeId  int
TimeValue   time
DayTimeText char
FlagMorning bit
Hour    tinyint
MinuteDay   smallint
MinuteHour  tinyint
SecondDay   int
SecondHour  smallint
SecondMinute    tinyint

Sample Data样本数据

App User Name   Access Date     TimeId  Hour    MinuteHour  SecondMinute    TimeValue   DateInvited TimeInvited
Mr x    24/02/2020  32222   8   57  2   08:57:02    23/02/2020 17:20    17:20:05

I need to work the time between in hours of the date invited and the First Access Date.我需要在受邀日期和首次访问日期之间的几小时内工作。 So the concepts of seperate time and date colmns in power bi has thrown me.因此,power bi 中单独的时间和日期列的概念让我感到厌烦。 Should I convert this to a combined date time in the Datawarehouse and then do a simple DATEDIFF in the power bi side or power query ?我应该将其转换为 Datawarehouse 中的组合日期时间,然后在 power bi side 或 power query 中执行简单的 DATEDIFF 吗?

Is there a simple way to do this in DAX and avoid introducing a combined date and time column ?是否有一种简单的方法可以在 DAX 中执行此操作并避免引入组合的日期和时间列?

To me, the easiest solution is to make the DateTime column either in the DWH or in power query (or in DAX).对我来说,最简单的解决方案是在 DWH 或电源查询(或 DAX)中创建 DateTime 列。 (better if done in power query) If you don't "materialize" the column, it will be re-calculated every time the expression is called and I'm not sure about how the performance can be. (如果在电源查询中完成更好)如果您不“实现”列,则每次调用表达式时都会重新计算它,我不确定性能如何。 (it's up to the number of rows). (这取决于行数)。 You can also set this column as hidden if you don't want it to be seen.如果您不想看到它,也可以将此列设置为隐藏。

--In Power Query use this function as column expression
#datetime(year as number, month as number, day as number, hour as number, minute as number, second as number)

--Using Dax Calculated Column
DateTimeCol = DATE ( YYYY, MM, DD ) + TIME ( hh, mm, ss )

--in a measure, you can then use the DATEDIFF function (or in the calculated column itself if you prefer)

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

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