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
deb_power123
Helper V
Helper V

DAX to compare two Dates and mark the column in Red and NA when the condition doesn't match

Hi All,

 

In my School table i have two columns :- 1) AttendanceLocalDate  2)ServerDate.

 

If AttendanceLocalDate column showing the attendance of students is equal to ServerDate of the attendance serverand the serverDate is equal to systemdate then only it should  populate the values of Attendance localtime, if AttendancelocalDate is not equal to ServerDate[which should also be equal to today's system date], then it should show "NA" with NA text in red color.

 

My Source table :

AttendancelocalDate Location StudentID Name     ServerDate
20.07.2021 11:05AMGate1101Tom20.07.2021 11:05AM
20.07.2021 10.03.22Gate1102Hary20.07.2021 10.03.22
20.07.2021 10.09.21Gate2103Rohan20.07.2021 10.09.21
20.07.2021 09.03.18Gate2105Mohan20.07.2021 09.03.18
19.07.2021 10.08.22Gate2109Sam19.07.2021 10.08.22
19.07.2021 10.03.12Gate2110Sally20.07.2021 10.03.12

 

My expected table matrix:

 

It should populate Attendance total column as NA with red text where the AttendancelocalDate is not equal to serverDate[which should be today's system date only so we need to check this condition as well].Server date also has the potential to show olddates so we need to check it is today's date as the second condition after checking the first condition of AttendancelocalDate equal to Serverdate

 

AttendancelocalDate Location StudentID Name      ServerDate
20.07.2021 11:05AMGate1101Tom20.07.2021 11:05AM
20.07.2021 10.03.22Gate1102Hary20.07.2021 10.03.22
20.07.2021 10.09.21Gate2103Rohan20.07.2021 10.09.21
20.07.2021 09.03.18Gate2105Mohan20.07.2021 09.03.18
NAGate2109Sam19.07.2021 10.08.22
NAGate2110Sally20.07.2021 10.03.12

 

Regards

Sameer

1 REPLY 1
Greg_Deckler
Super User
Super User

@deb_power123 Try creating two columns. Use the numeric column for your conditional formatting.

Column = 
    SWITCH(TRUE(),
        INT(TODAY()) <> INT([ServerDate]),0,
        [AttendancelocalDate] <> [ServerDate],0,
        1
    )

Column 2 = 
    SWITCH(TRUE(),
        INT(TODAY()) <> INT([ServerDate]),"NA",
        [AttendancelocalDate] <> [ServerDate],"NA",
        [AttendancelocalDate] & ""
    )

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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.