Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Sum Value Over Relative Date Range

Hello,

 

I have a table like this:

WorkOrderWhseComponentItemNumberQtyIssuedQtyCommittedWODueDate_CCOrderStatus
008332200000-2016163001/5/2023C
HZ152W100000-201616101/16/2023C
HY371-200000-201616301/20/2023C
HX400-100000-2016160101/30/2023F
HX943-100000-201616202/9/2023C
HY201-200000-201616012/15/2023F
HY732W100000-201616012/16/2023F
HY582-200000-201616023/10/2023F
HW992-100000-201616024/14/2023F
HZ948-100000-201616025/2/2023F
HX675-100000-201616015/17/2023F
HX678-900000-201616018/17/2023F
HX672-300000-2016160110/19/2023F
HX677-700000-2016160111/11/2023F

I need to sum the QTYCommited where the Orderstatus = "F" & the WODueDate is within the last two months, or within the next 3 months. How would this be written? 

I came up with this -

TotalNeededforCommit2 = CALCULATE(SUM(WO2_WorkOrderMaterialDetail[QtyCommitted]), WO2_WorkOrderMaterialDetail[OrderStatus] = "F" && WO2_WorkOrderMaterialDetail[WODueDate_CC] >= DATEADD(Today(), -2, MONTH) &&  WO2_WorkOrderMaterialDetail[WODueDate_CC] <= DATEADD(Today(), 6, MONTH))

but I'm getting the error "A function DATEADD has been used in a true/false expression that is used as a table filter expression. This is not allowed."

What other dax function should I be using for this? Am I missing something? 

Thanks

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous ,

     

    The return value of DATEADD() is a table with a single column. You are using a date to compare with a table.

    DATEADD

     

    Try this:

    TotalNeededforCommit2 = 
    CALCULATE (
        SUM ( WO2_WorkOrderMaterialDetail[QtyCommitted] ),
        WO2_WorkOrderMaterialDetail[OrderStatus] = "F"
            && WO2_WorkOrderMaterialDetail[WODueDate_CC] >= EDATE(TODAY(),-3)
            && WO2_WorkOrderMaterialDetail[WODueDate_CC] <= EDATE(TODAY(),6)
    )

    EDATE

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    The return value of DATEADD() is a table with a single column. You are using a date to compare with a table.

    DATEADD

     

    Try this:

    TotalNeededforCommit2 = 
    CALCULATE (
        SUM ( WO2_WorkOrderMaterialDetail[QtyCommitted] ),
        WO2_WorkOrderMaterialDetail[OrderStatus] = "F"
            && WO2_WorkOrderMaterialDetail[WODueDate_CC] >= EDATE(TODAY(),-3)
            && WO2_WorkOrderMaterialDetail[WODueDate_CC] <= EDATE(TODAY(),6)
    )

    EDATE

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you much!