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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
craigL01
New Member

Multiple IF AND DAX statement not working

I have written the following DAX . Its basically looking at 3 date fields on a sql AX database so 01/01/1900 is no date. The first IF is checking there is a date in LETTERSENTDATE01 and there is not a date in LETTERSENTDATE02 result being 1, then the next IF checks there are dates on 01 and 02 and not in 03 result being 2 and the final IF chaecks there are dates in 01, 02 and 03 result being 3.

 

Visits = IF(PROJTABLE[MXMSURVEYLETTERSENTDATE01]>01/01/1900 && PROJTABLE[MXMSURVEYLETTERSENTDATE02]=01/01/1900,1,
IF(PROJTABLE[MXMSURVEYLETTERSENTDATE01]>01/01/1900 && PROJTABLE[MXMSURVEYLETTERSENTDATE02]>01/01/1900 && PROJTABLE[MXMSURVEYLETTERSENTDATE03]=01/01/1900,2,
IF(PROJTABLE[MXMSURVEYLETTERSENTDATE01]>01/01/1900 && PROJTABLE[MXMSURVEYLETTERSENTDATE02]>01/01/1900 && PROJTABLE[MXMSURVEYLETTERSENTDATE03]>01/01/1900,3,0)))
When it runs it marks evety record with 3 totally ignoring the first two if statements
 
i did a quick little data table in BI just to show the field results and values and you can see i have lines that should have a visits of 2 and 1.
craigL01_0-1646301647725.png

 

Appreciate any help you can give

 
 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @craigL01 
You need to use proper date data type

Visits =
IF (
    PROJTABLE[MXMSURVEYLETTERSENTDATE01] > DATE ( 1900, 01, 01 )
        && PROJTABLE[MXMSURVEYLETTERSENTDATE02] = DATE ( 1900, 01, 01 ),
    1,
    IF (
        PROJTABLE[MXMSURVEYLETTERSENTDATE01] > DATE ( 1900, 01, 01 )
            && PROJTABLE[MXMSURVEYLETTERSENTDATE02] > DATE ( 1900, 01, 01 )
            && PROJTABLE[MXMSURVEYLETTERSENTDATE03] = DATE ( 1900, 01, 01 ),
        2,
        IF (
            PROJTABLE[MXMSURVEYLETTERSENTDATE01] > DATE ( 1900, 01, 01 )
                && PROJTABLE[MXMSURVEYLETTERSENTDATE02] > DATE ( 1900, 01, 01 )
                && PROJTABLE[MXMSURVEYLETTERSENTDATE03] > DATE ( 1900, 01, 01 ),
            3,
            0
        )
    )
)

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @craigL01 
You need to use proper date data type

Visits =
IF (
    PROJTABLE[MXMSURVEYLETTERSENTDATE01] > DATE ( 1900, 01, 01 )
        && PROJTABLE[MXMSURVEYLETTERSENTDATE02] = DATE ( 1900, 01, 01 ),
    1,
    IF (
        PROJTABLE[MXMSURVEYLETTERSENTDATE01] > DATE ( 1900, 01, 01 )
            && PROJTABLE[MXMSURVEYLETTERSENTDATE02] > DATE ( 1900, 01, 01 )
            && PROJTABLE[MXMSURVEYLETTERSENTDATE03] = DATE ( 1900, 01, 01 ),
        2,
        IF (
            PROJTABLE[MXMSURVEYLETTERSENTDATE01] > DATE ( 1900, 01, 01 )
                && PROJTABLE[MXMSURVEYLETTERSENTDATE02] > DATE ( 1900, 01, 01 )
                && PROJTABLE[MXMSURVEYLETTERSENTDATE03] > DATE ( 1900, 01, 01 ),
            3,
            0
        )
    )
)

Brilliant thanks works fine now.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.