查找两个日期之间的差异,不包括非工作日

时间:2019-06-13 17:26:56

标签: powerbi dax

需要两个日期之间的结果天数,不包括非工作日。

enter image description here

一些定义

Sales[date1]
Sales[date2]

DeterminesWeekDay = WEEKDAY(Payment[Deposit Date],3) 


Weekend -Weekday = 
SWITCH(TRUE(),
    Sales[DeterminesWeekDay] = 0, "Weekday",
    Sales[DeterminesWeekDay] = 1, "Weekday",
    Sales[DeterminesWeekDay] = 2, "Weekday",
    Sales[DeterminesWeekDay] = 3, "Weekday",
    Sales[DeterminesWeekDay] = 4, "Weekday",
    Sales[DeterminesWeekDay] = 5, "Weekend",
    Sales[DeterminesWeekDay] = 6, "Weekend",
    BLANK()
)

我坚持使用dax函数,创建新的度量或列。

WorkDaysOnly = 
CALCULATE(DATEDIFF(MIN(Sales[date1]),MIN(Sales[date2]),DAY),
        FILTER(Sales, Sales[Weekend -Weekday] = "Weekday") )

在这里我不知道如何选择两个日期之间的差值,仍然是周末。

示例,date1 = 6/7/2019和date2 = 6/10/2019,我期望的是一天而不是3天。最好复制我的日期列并删除所有周末日期,怎么办?

1 个答案:

答案 0 :(得分:0)

请创建以下措施

No of working days = CALCULATE(SUM('calendar'[isWroking]),DATESBETWEEN('calendar'[Date],Sales[Date 1],Sales[Date 2]))


   isWroking = IF(WEEKDAY('calendar'[Date],2)<=5,1,0)

**请注意,应该在日历表中创建工作