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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
gauravnarchal
Post Prodigy
Post Prodigy

If date is Less than greater than today Measure

Hello

 

I want to create a measure to get the result as–

 

If the contract date is 1-Jan-00  then return “Contract Expired – High”

If the contract end date is within 60days as of today then return “Contract Expiring Soon – Level 2”

If the contract end date is within 30days as of today then return “Contract Expiring Soon – Level 1”

If the contract end date is less than or equal to “as of today” then return “Contract Expired”

Else

"Contract Valid"

 

I have attached the PBIX for your reference - Download Here

 

Thanks

Gaurav

 

 

Contract Start DateContract End Date
15-Feb-1814-Feb-21
1-Apr-171-Jan-00
28-Jan-1427-Jan-21
1-Jan-1831-Dec-21
19-Nov-2021-Nov-21
4-Aug-1930-Jul-21
1-Jul-1630-Jun-21
21-May-2021-May-21
1-Sep-171-Sep-20
15-Jan-2015-Jan-21
20-Aug-1320-Aug-11
1-Apr-191-Apr-20
1-Apr-191-Apr-20
31-Aug-2031-Oct-23
2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression in a table visual with your end date column.

 

Contract Status =
VAR vDaysFromExpiry =
    DATEDIFF (
        TODAY (),
        MIN ( Sheet1[Contract End Date] ),
        DAY
    )
VAR vSwitch =
    SWITCH (
        TRUE (),
        vDaysFromExpiry < 0"Contract Expired",
        vDaysFromExpiry <= 30"Contract Expiring Soon - Level 1",
        vDaysFromExpiry <= 60"Contract Expiring Soon - Level 2",
        "Other"
    )
RETURN
    IF (
        MIN ( Sheet1[Contract End Date] )
            DATE ( 200011 ),
        "Contract Expired - High",
        vSwitch
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

v-janeyg-msft
Community Support
Community Support

Hi, @gauravnarchal 

 

It’s my pleasure to answer for you.

You can modify the previous formula like this:

2.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

4 REPLIES 4
v-janeyg-msft
Community Support
Community Support

Hi, @gauravnarchal 

 

It’s my pleasure to answer for you.

You can modify the previous formula like this:

2.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

mahoneypat
Microsoft Employee
Microsoft Employee

That seems to be working for me (see pic).  If you resend your pbix, I can take a look.

 

mahoneypat_0-1607970131308.png

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression in a table visual with your end date column.

 

Contract Status =
VAR vDaysFromExpiry =
    DATEDIFF (
        TODAY (),
        MIN ( Sheet1[Contract End Date] ),
        DAY
    )
VAR vSwitch =
    SWITCH (
        TRUE (),
        vDaysFromExpiry < 0"Contract Expired",
        vDaysFromExpiry <= 30"Contract Expiring Soon - Level 1",
        vDaysFromExpiry <= 60"Contract Expiring Soon - Level 2",
        "Other"
    )
RETURN
    IF (
        MIN ( Sheet1[Contract End Date] )
            DATE ( 200011 ),
        "Contract Expired - High",
        vSwitch
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat  - Thank you for the advice.. I had created the measure and it is showing the desired result, when i try to filter the results status from "Filter on this visual"  i am not able to do it. Can you please help!

 

gauravnarchal_0-1607969395589.png

 

gauravnarchal_1-1607969484606.png

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.