简体   繁体   English

Power BI:用于查找日期之间天数的 DAX 公式给出“遇到了日期值的无效数字表示”错误

[英]Power BI: DAX formula to find number of days between dates gives "an invalid numeric representation of a date value was encounted" error

I've just recently begun using Power BI and DAX for my new job, so if this is a super simple or stupid fix I apologize.我最近才开始在我的新工作中使用 Power BI 和 DAX,所以如果这是一个超级简单或愚蠢的修复,我深表歉意。

I'm trying to create a column (NumDays) that calculates the number of days within a date range, and a column (NumWorkDays) that calculates the number of work days between the date range.我正在尝试创建一个列 (NumDays) 来计算日期范围内的天数,以及一个列 (NumWorkDays) 来计算日期范围之间的工作日数。 I have a table (Calendar) that contains a list of dates and indicates with 1 or 0 whether it's a work day or not (Mon-Fri).我有一个表(日历),其中包含一个日期列表,并用 1 或 0 指示它是否是工作日(周一至周五)。 In a separate table (Shipments), I have two date values I'm trying to find the number of work days between: DateOfDelivery and DateOfSale.在一个单独的表(发货)中,我有两个日期值,我试图找到它们之间的工作日数:DateOfDelivery 和 DateOfSale。

Here are my DAX formulas for both columns...这是我的两列 DAX 公式...

NumDays:天数:

NumDays = IF(ISBLANK('Shipments'[DateOfDelivery]), -1, CALCULATE(COUNTROWS('Calendar'),DATESBETWEEN('Calendar'[Dates],'Shipments'[DateOfSale], 'Shipments'[DateOfDelivery])))

NumWorkDays:工作日数:

NumWorkDays = IF(ISBLANK('Shipments'[DateOfDelivery]), -1, CALCULATE(SUM('Calendar'[IsWorkDay]),DATESBETWEEN('Calendar'[Dates],'Shipments'[DateOfSale], 'Shipments'[DateOfDelivery])))

Whenever I try to run either formula, I get this error:每当我尝试运行任一公式时,我都会收到此错误:

An invalid numeric representation of a date value was encountered.遇到了日期值的无效数字表示。

And that's it.就是这样。 I've gone through both tables looking for weird values, and I've double checked the data types to make sure they are datetimes and not something funky.我浏览了两个表以寻找奇怪的值,并且我仔细检查了数据类型以确保它们是日期时间而不是奇怪的东西。 Honestly I'm pretty stumped here, so any help would be appreciated.老实说,我在这里很困惑,所以我们将不胜感激。 Thanks in advance!提前致谢!

**Edit: I've tried breaking down the parts of each formula to try and pinpoint where the error is being caused. **编辑:我尝试分解每个公式的各个部分以尝试查明导致错误的位置。 It seems like it's originating from the DATESBETWEEN() function, but I can't narrow it down to a particular column or table causing the issue.它似乎源自 DATESBETWEEN() function,但我无法将其缩小到导致问题的特定列或表。 Is this just a known issue with that function??这只是 function 的一个已知问题吗?

Got an answer from someone on the Power BI Community forums... Turns out using DATESBETWEEN() wasn't the right way to go. 在Power BI社区论坛上得到某人的答案...结果证明使用DATESBETWEEN()不是正确的方法。

Updated NumDays: 更新的NumDays:

NumDays = IF(ISBLANK('Shipments'[DateOfDelivery]), -1, CALCULATE(COUNTROWS('Calendar'),filter('Calendar', 'Calendar'[Dates]>('Shipments'[DateofSale]) && 'Calendar'[Dates]<=(''[Delivered]))))

Updated NumWorkDays: 更新的NumWorkDays:

NumWorkDays = IF(ISBLANK('Shipments'[DateOfDelivery]), -1, CALCULATE(COUNTROWS('Calendar'), filter('Calendar', 'Calendar'[Dates]>('Shipments'[DateofSale]) && 'Calendar'[Dates]<=('Shipments'[DateOfDelivery])&& 'Calendar'[WorkDay]=1)))

Here's the link to the post on their site: http://community.powerbi.com/t5/Desktop/DATESBETWEEN-gives-quot-Invalid-Numeric-Representation-of-a-Date/mp/42604#M16306 这是他们网站上帖子的链接: http : //community.powerbi.com/t5/Desktop/DATESBETWEEN-gives-quot-Invalid-Numeric-Representation-of-a-Date/mp/42604#M16306

Please check dates in the tables.请检查表格中的日期。

In my experience I have received the same error when in a table I put rows and in a line there was a wrong date with year equals to 9999. The strange things is that date column hasn't been used in any DAX formula.根据我的经验,当我在表格中放置行时,我收到了同样的错误,并且在一行中有一个错误的日期,年份等于 9999。奇怪的是日期列没有在任何 DAX 公式中使用。

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

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