【问题标题】:Power BI - Date calculations for a non standard monthPower BI - 非标准月份的日期计算
【发布时间】:2021-04-30 13:26:09
【问题描述】:

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 日完成 = 积压
创建于 2021 年 4 月 20 日,未完成,今天 [2021 年 4 月 30 日] = 积压
创建于 2021 年 4 月 29 日,未完成,今天 [2021 年 4 月 30 日] = 当前

我编写了以下 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]))

【问题讨论】:

    标签: date dax powerbi-desktop


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。我很欣赏有关性能的建议,但我更多的是寻找更好的解决方案,因为这个解决方案并不完全有效。例如,所有未完成的工单都显示为“积压”状态,即使应该有一些处于“当前”状态。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多