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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors