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
BrookeO3
Regular Visitor

PowerBI/Power Query Formulas

Hi, I am trying to create a custom column in PowerBI via power query but I can't seem to get the correct formula. I need to determine if a date is </> 6 months & then have the new column populated with "Current" or "OAI" based on the true/false value. 

So...

 

If {Column w/ Date} >6 months from today then "OAI"

If {Column w/ Date} <6 months from today then "Current"

 

 

Thanks in advance for your help! 

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

Hi @BrookeO3 ,

You can get the inventory status by adding a custom column in Power Query Editor or DAX, please find the details in the attachment.

1. Create a custom column in Power Query Editor just as suggested by @pranit828 

Here it need to make some change in his formula as below, the part with red font is updated one:

=if [Last fulfillment date] > Date.AddMonths(Date.From(DateTime.LocalNow()), - 6) then "Current" else "OAI"

Add custom column in Power Query EditorAdd custom column in Power Query Editor

2. Create a calculated column as below by DAX

Column = 
IF (
    DATEDIFF ( 'Table'[Last fulfillment date], TODAY (), MONTH ) > 6,
    "OAI",
    "Current"
)

yingyinr_1-1639734316271.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

5 REPLIES 5
v-yiruan-msft
Community Support
Community Support

Hi @BrookeO3 ,

You can get the inventory status by adding a custom column in Power Query Editor or DAX, please find the details in the attachment.

1. Create a custom column in Power Query Editor just as suggested by @pranit828 

Here it need to make some change in his formula as below, the part with red font is updated one:

=if [Last fulfillment date] > Date.AddMonths(Date.From(DateTime.LocalNow()), - 6) then "Current" else "OAI"

Add custom column in Power Query EditorAdd custom column in Power Query Editor

2. Create a calculated column as below by DAX

Column = 
IF (
    DATEDIFF ( 'Table'[Last fulfillment date], TODAY (), MONTH ) > 6,
    "OAI",
    "Current"
)

yingyinr_1-1639734316271.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.
BrookeO3
Regular Visitor

Hi again. I think the formula is correct, but I am getting an error in my new column. 

BrookeO3_0-1639599499853.pngBrookeO3_1-1639599519754.png

 

 

pranit828
Community Champion
Community Champion

Hi @BrookeO3 

Please use the below code

= Table.AddColumn(#"Changed Type6", "FinancialYear", each if [DateCaseCreated] < Date.AddMonths(getdate(), -6) then "Current" else "OAI" )





PBI_SuperUser_Rank@1x.png


Hope it resolves your issue? 
Did I answer your question? Mark my post as a solution!

Appreciate your Kudos, Press the thumbs up button!!
Linkedin Profile

Hi, thanks for your response. I am getting an error in the "getdate" part of the formula - I can't figure out what I am missing. 

BrookeO3_0-1639503463286.png

 

@BrookeO3  replace getdate with Date.From(DateTime.LocalNow())

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.