Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MikeHunt
Regular Visitor

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"
            )
        )
    )
)
1 ACCEPTED SOLUTION
v-nuoc-msft
Community Support
Community Support

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”

vnuocmsft_0-1711950532241.png

 

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.

 

vnuocmsft_1-1711950618484.png

 

Regards,

Nono Chen

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

 

 

View solution in original post

3 REPLIES 3
v-nuoc-msft
Community Support
Community Support

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”

vnuocmsft_0-1711950532241.png

 

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.

 

vnuocmsft_1-1711950618484.png

 

Regards,

Nono Chen

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

 

 

Ahmedx
Super User
Super User

I checked the measure again
Ahmedx
Super User
Super User

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"
            )

 

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.