Forum Discussion

MikeHunt's avatar
MikeHunt
Regular Visitor
2 years ago
Solved

Remaining days calculation based on a date column

I want to calculate remaining days in DAX based on NextRevision date column. Could you please help?
Example formula below. 

Due Date =
IF(tbl_Materials[NextRevision] <= TODAY(), "Overdue",
    IF(tbl_Materials[NextRevision] <= 30, "Less than 30 days",
        IF(tbl_Materials[NextRevision] <= 60, "Less than 60 days",
            IF(tbl_Materials[NextRevision] <= 90, "Less than 90 days",
                "In Compliance"
            )
        )
    )
)
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi MikeHunt 

     

    Ahmedx Thank you very much for your prompt reply!

     

    When I was checking the posts in our community, I found your post. May I ask if your issue has been resolved? If not, here I have provided an alternative code logic, please refer to the following method:

     

    Here's some dummy data

     

    “Table”

     

    Create a measure.

    MEASURE = 
    VAR _Diff = DATEDIFF(SELECTEDVALUE('Table'[NextRevision]), TODAY(), DAY)
    RETURN
    SWITCH(
        TRUE, 
        _Diff <= 0, "Overdue",
        0 < _Diff && _Diff <= 30, "Less than 30 days",
        30 < _Diff && _Diff <= 60, "Less than 60 days",
        60 < _Diff && _Diff <= 90, "Less than 90 days",
        "In Compliance"
    )

     

    Here is the result.

     

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

3 Replies

  • pls try this code

     

     

    Due Date =
    VAR _Diff = DATEDIFF( TODAY(),tbl_Materials[NextRevision] ,DAY)
    RETURN
    
    SWITCH(TRUE, 
       _Diff <= 0 "Overdue",
        _Diff <= 30, "Less than 30 days",
          _Diff <= 60, "Less than 60 days",
               _Diff <= 90, "Less than 90 days",
                    "In Compliance"
                )
    
    ===== or ===
     
     MEASURE  =
    VAR _Diff = DATEDIFF(TODAY(),MAX(tbl_Materials[NextRevision] ) ,DAY)
    RETURN
    
    SWITCH(TRUE, 
       _Diff <= 0 "Overdue",
        _Diff <= 30, "Less than 30 days",
          _Diff <= 60, "Less than 60 days",
               _Diff <= 90, "Less than 90 days",
                    "In Compliance"
                )

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MikeHunt 

     

    Ahmedx Thank you very much for your prompt reply!

     

    When I was checking the posts in our community, I found your post. May I ask if your issue has been resolved? If not, here I have provided an alternative code logic, please refer to the following method:

     

    Here's some dummy data

     

    “Table”

     

    Create a measure.

    MEASURE = 
    VAR _Diff = DATEDIFF(SELECTEDVALUE('Table'[NextRevision]), TODAY(), DAY)
    RETURN
    SWITCH(
        TRUE, 
        _Diff <= 0, "Overdue",
        0 < _Diff && _Diff <= 30, "Less than 30 days",
        30 < _Diff && _Diff <= 60, "Less than 60 days",
        60 < _Diff && _Diff <= 90, "Less than 90 days",
        "In Compliance"
    )

     

    Here is the result.

     

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.