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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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