Power BI - 非标准月份的日期计算

时间:2021-04-30 13:26:09

标签: date dax powerbi-desktop

Power BI 桌面
版本:2.73.5586.984 64 位(2019 年 9 月)

我正在创建一个计算列,以确定工单是否已在“当前”或“积压”状态下完成。我们的报告期月份是从当月的 26 日到 25 日。如果工单在报告期间 m/26 - m/25 内完成,它将被视为“当前”。如果工单在该时间范围之外完成,那么它将是“积压”。此外,如果当前工单尚未完成但仍有可能在同一报告期内完成,则该工单将被列为“当前”,但如果继续到下一个报告月份,则它将被列为“积压”。 "

<块引用>

示例:
2021 年 1 月 1 日创建 & 2021 年 1 月 10 日完成 = 当前
2021 年 1 月 1 日创建并于 2021 年 3 月 18 日完成 = 待办事项
2021 年 1 月 25 日创建 & 2021 年 1 月 26 日完成 = 待办事项
创建于 4/20/2021 & 未完成 & 今天 [4/30/2021] = 待办事项
创建于 4/29/2021 & 未完成 & 今天 [4/30/2021] = 当前

我编写了以下 DAX 来处理这个问题,但我似乎在报告期结束后/开始时遇到了问题,其中计算无法正常工作,所有内容都列为当前或积压。

我的日期表中还有一个辅助列,用于根据当天确定当前报告期间的内容,但我没有在此公式中使用它,但如果它可以提高效率,则可以。

什么是更好/正确的方法来做到这一点?

当前/积压计算列:

Current_Backlog = 

VAR CreatedDay = Day(IR_SR[Created_Date])
VAR CompletedDay = Day(IR_SR[Completed_Date])
VAR CreatedMonth = Month(IR_SR[Created_Date])
VAR CompletedMonth = Month(IR_SR[Completed_Date])
VAR CreatedMonthAdd = Month(IR_SR[Created_Date])+1
VAR CompletedMonthAdd = Month(IR_SR[Completed_Date])+1
VAR CurrentMonth = Month(TODAY())
VAR CurrentMonthAdd = Month(TODAY())+1
VAR CurrentDay = Day(TODAY())

RETURN
//If the date the ticket was completed is before the 26th and the created and completed month match, mark as current
IF(CompletedDay < 26 && CreatedMonth = CompletedMonth, "Current",
    //If the completed date is after or equal to the 26th see if the created month plus one and completed month plus one match, mark as current
    IF(CreatedDay >= 26 && CompletedDay >= 26 && CreatedMonthAdd = CompletedMonthAdd, "Current",
        //If the completed date is after or equal to the 26th and the created date is after or equal to the 26th see if the created and completed month plus one match, mark as current
        IF(CreatedDay >= 26 && CreatedMonthAdd = CompletedMonth, "Current",
            //If the ticket is not completed and the created date is less then the 26th and the created month and current month match, mark as current
            IF(IR_SR[Open/Closed] = "Open" && CurrentDay < 26 && CreatedDay < 26 && CreatedMonth = CurrentMonth, "Current",
                //If the ticket is not completed and the created date is greater then the 26th and the created month and current month match plus one, mark as current
                IF(IR_SR[Open/Closed] = "Open" && CurrentDay >= 26 && CurrentDay < 1 && CreatedDay >= 26 && CreatedMonthAdd = CurrentMonthAdd, "Current",
                    IF(IR_SR[Open/Closed] = "Open" && CurrentDay < 26 && CurrentDay >= 1 && CreatedDay >= 26 && CreatedMonthAdd = CurrentMonth, "Current",
                    "Backlog"))))))

当前报告月份:

= Table.AddColumn(#"Inserted Day Name", "Reporting_Period", each if Date.Day([Date]) >= 26
then Date.StartOfMonth(Date.AddMonths([Date], 1))
else Date.StartOfMonth([Date]))

1 个答案:

答案 0 :(得分:0)

在这种情况下的建议。在 Power BI 内的性能分析器中比较两个 DAX 公式,并检查计算花费了多少时间。 我猜你所有的数据都被导入了,在这种情况下数据被缓存,所以关于性能的第一个问题解决了。 无论如何,粘贴您的 DAX 代码的第二部分,我会检查它。 谢谢