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
alanphamvistra4
Frequent Visitor

Create Custom Column using PQL IF Statement Logic to Compare A Date to the Current Date

I need a PQL script to create a new column that essentially does the following for each entry

 

If [Expiration Date} is before [Current Date], then return "Expired"

If [Expiration Date} is within 30 days after [Current Date], then return "Expiring"

Else "Active"

I have been playing around with M and DAX languages and can't figure out how to properly return "Expiring" if an entry will become expired in less then 30 days but is still technically Active since it has not expired yet.

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @alanphamvistra4 ,

You can follow the below methods to achieve it, please find the details in the attachment.

1. By M query: add a custom column

=if [Expiration Date]<Date.From(DateTime.LocalNow()) then "Expired" 
else if [Expiration Date]>=Date.From(DateTime.LocalNow()) and [Expiration Date]<=Date.AddDays(Date.From(DateTime.LocalNow()),30) then "Expiring" 
else "Active"

yingyinr_1-1674006636415.png

2. By DAX: create a calculated column as below to get it

Status = 
SWITCH (
    TRUE (),
    'Table'[Expiration Date] < TODAY (), "Expired",
    'Table'[Expiration Date] >= TODAY ()
        && 'Table'[Expiration Date]
            <= TODAY () + 30, "Expiring",
    "Active"
)

yingyinr_0-1674006168464.png

Best Regards

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @alanphamvistra4 ,

You can follow the below methods to achieve it, please find the details in the attachment.

1. By M query: add a custom column

=if [Expiration Date]<Date.From(DateTime.LocalNow()) then "Expired" 
else if [Expiration Date]>=Date.From(DateTime.LocalNow()) and [Expiration Date]<=Date.AddDays(Date.From(DateTime.LocalNow()),30) then "Expiring" 
else "Active"

yingyinr_1-1674006636415.png

2. By DAX: create a calculated column as below to get it

Status = 
SWITCH (
    TRUE (),
    'Table'[Expiration Date] < TODAY (), "Expired",
    'Table'[Expiration Date] >= TODAY ()
        && 'Table'[Expiration Date]
            <= TODAY () + 30, "Expiring",
    "Active"
)

yingyinr_0-1674006168464.png

Best Regards

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

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!

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.