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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

IF Statement with dates

Hi Community!

 

I'm am looking to see if somone can help me out with this DAX formula.

 

The ultimate result I am looking for is, if a last order date is prior to 8/1, the Customer Ordered column would reflect "No". 

 

You can see in the highilighted area below, my current dax formula isn't giving me the correct result.

 

Christina_C_0-1692897043190.png

 

My current formula is:

Customer Ordered = 
var Firstdayofmonth = EOMONTH(TODAY(), -1) +1
var Lastorderdate = CALCULATE(MAX(Sales_Invoices[Posting Date]), FILTER(Sales_Invoices,Sales_Invoices[Type] = "Invoice" || Sales_Invoices[Type] = "Open Order"))
var Result = 
IF(Lastorderdate >=Firstdayofmonth,"Yes", "No")
RETURN 
Result

 

Thank you so much in advance! 

 

Gratefully, 

Christina

5 REPLIES 5
technolog
Super User
Super User

I hope this message finds you well. I've noticed that this solution remain unresolved. If any of you have managed to find a resolution to the issue, I kindly request that you share your solution for the benefit of the entire community. Alternatively, if you're still facing challenges, please do let us know as well.

Your insights and updates will greatly assist others who might be encountering the same challenge.

Syk
Super User
Super User

Are you sure the variable you're using "Lastorderdate" is the same as what you have in your column as last order date?
To test just temporarily change your return to lastorderdate instead of result

Anonymous
Not applicable

@Syk  Thank you for the response!

 

Oh wow, even though I used the same formula for the "Last Order Date" column, the variable in this formula is returning with 9/7/23 for all customers (which is the last posting date for all orders). 

 

I'm guessing I need to somehow summarize the formula to include the Customer Code.  Do you by chance, have any suggestions?

 

Christina_C_2-1692910479047.png

 

Thank you again! 

Christina

 

Anonymous
Not applicable

Hi @Anonymous 

You can try the following measure

Customer Ordered =
VAR Firstdayofmonth =
    EOMONTH ( TODAY (), -1 ) + 1
VAR Lastorderdate =
    CALCULATE (
        MAX ( Sales_Invoices[Posting Date] ),
        FILTER (
            ALLSELECTED ( Sales_Invoices ),
            [Customer Code]
                IN VALUES ( Sales_Invoices[Customer Code] )
                    && OR ( Sales_Invoices[Type] = "Invoice", Sales_Invoices[Type] = "Open Order" )
        )
    )
VAR Result =
    IF ( Lastorderdate >= Firstdayofmonth, "Yes", "No" )
RETURN
    Result

 

Best Regards!

Yolo Zhu

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

Anonymous
Not applicable

Hi  @Anonymous ,

 

Thank you for the response! 🙂 

 

I imputed the recommended formula:

 

Customer Ordered = 
var Firstdayofmonth = EOMONTH(TODAY(), -1) +1
var Lastorderdate = 
    CALCULATE(
        MAX(Sales_Invoices[Posting Date]), 
        FILTER(
            ALLSELECTED(Sales_Invoices),
            [Customer Code]
                IN VALUES (Sales_Invoices[Customer Code])
                    && OR (Sales_Invoices[Type] =  "Invoice", Sales_Invoices[Type] = "Open Order")
        )
    )
var Result = 
IF(Lastorderdate >=Firstdayofmonth,"Yes", "No")
RETURN 
Result

And got this as a result: 

 

Christina_C_2-1693320182812.png

 

Since I want to show all customers whether they have ordered or not - my Customer comes from my Dim CUSTOMER table, so I tried this: 

Customer Ordered = 
var Firstdayofmonth = EOMONTH(TODAY(), -1) +1
var Lastorderdate = 
    CALCULATE(
        MAX(Sales_Invoices[Posting Date]), 
        FILTER(
            ALLSELECTED(CUSTOMER),
            [Customer Code]
                IN VALUES (Sales_Invoices[Customer Code])
                    && OR (Sales_Invoices[Type] =  "Invoice", Sales_Invoices[Type] = "Open Order")
        )
    )
var Result = 
IF(Lastorderdate >=Firstdayofmonth,"Yes", "No")
RETURN 
Result

 

Christina_C_3-1693320584777.png

 

The formula does show "No" correctly, however my credit memos are now separate from my Invoices and Open Orders.

 

When I sort by customer code - you can see more clearly that credit memos are treated as separate from Invoices and Open Orders. (note:  credit memos are located in the same table 'Sales_Invoices' - under Type:  Credit Memo)

 

Christina_C_5-1693320792050.png

 

Seems like I need to do just a small tweak to the formula, but can't figure out what that is.  Any suggestions?

 

Thank you so much, again! 

Christina

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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