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

DAX to determine the date column with null value and display it as per Date slicer selection

Hi Everyone,

 

I have a typical scenario as below.

I have a student table and it contains four columns as below :-

 

1.StudentID
2. StudentName
3.LastAttendanceDate
4.StudentType

 

Now there are some null values in the date column LastAttendanceDate.Is it possible to use a date slicer to show these values of the students who have LastAttendanceDate column value as null? In simple words: Say you are a student who went to a school on Monday,Tuesday and Friday and you were absent on Wednesday and Thursday so here wednesday and Thursday are the days where you were absent in the week and we need to display these records in the table visualization . 

 

My excel Input data:-

StudentIDStudentNameLastAttendanceDateStudentType
100Mary02-05-2011 10:45Fulltime
100Mary Fulltime
100Mary04-05-2011 12:45Fulltime
100Mary06-05-2011 15:45Fulltime
100Mary Fulltime
100Mary08-05-2011 19:45Fulltime
100Mary09-05-2011 12:45Fulltime
101John02-05-2011 10:45Part Time
101John03-05-2011 11:23Part Time
101John04-05-2011 10:45Part Time
101John06-05-2011 15:49Part Time
101John Part Time
101John08-05-2011 19:45Part Time
101John09-05-2011 12:45Part Time

 

so here I need to dynamically find in the week/month range or any dynamic date range say  from date range 02-05-2011 and 08-05-2011 or 02-05-2011 and 09-05-2011 or even 06-05-2011 and 09-05-2011,  the students who were absent and show it in my table visualization.

 

Can anyone provide an approach or any helpful DAX? Appreciate for all the help

 

My present visualization looks like this : I want to show the students who were absent in the given timerange as selected in the dateslicer.

 

5.JPG

 

so if I slide the date slicer as per minimum and maximum ranges, it should show all the rows of students who were absent or with null values for Last Attendance Date column in those time range.

 

Kind regards

Sameer

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @deb_power123 ,

 

I assume you calendar is connected with the last date, also that the weekends are not school days so I have added the following measure:

Absent =
VAR temp_table_Names =
    FILTER (
        SELECTCOLUMNS ( ALL ( 'Table'[StudentName] ), "Name", 'Table'[StudentName] ),
        NOT ( [Name] IN VALUES ( 'Table'[StudentName] ) )
    )
VAR result =
    CONCATENATEX ( temp_table_Names, [Name], ", " )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( 'calendar'[weekday] ) = "weekday", IF ( ISBLANK ( result ), "", result )
    )

 

This will give result below:

MFelix_0-1615396540968.png

 

 

Check PBIx file attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

7 REPLIES 7
MFelix
Super User
Super User

Hi @deb_power123 ,

 

I assume you calendar is connected with the last date, also that the weekends are not school days so I have added the following measure:

Absent =
VAR temp_table_Names =
    FILTER (
        SELECTCOLUMNS ( ALL ( 'Table'[StudentName] ), "Name", 'Table'[StudentName] ),
        NOT ( [Name] IN VALUES ( 'Table'[StudentName] ) )
    )
VAR result =
    CONCATENATEX ( temp_table_Names, [Name], ", " )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( 'calendar'[weekday] ) = "weekday", IF ( ISBLANK ( result ), "", result )
    )

 

This will give result below:

MFelix_0-1615396540968.png

 

 

Check PBIx file attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thankyou, and I will say this is the best technique you made me learn.I may have some more variations in the data and I will seek your suggestions in those case scenarios.I mostly have the column value in date time instead of date.But thnakyou for your answer, it helped

Hi @MFelix 

I tried to replicate the DAX formula you provided in a different set of data  but i am getting both employee names in absent list as per screenshot below:-

error.JPG

 

Have you made any additional configurations or change apart of the measures? Please find below the link for the .pbix file .

 

could you please suggest where I am making a mistake in the below file?

my pbix file 

 

Kind regards

Sameer

Hi @deb_power123 ,

 

The relationship between the calendar table and the attendance table needs to be done on date level so you need to format both columns of the relationship has date and then make the relationship.

 

Your file has the data connected to an excel spreadsheet so I cannot change it directly, but what you need to do is to create a date on column on your attendance table and format the calendar table as da date column, then everything should work properly.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thankyou for the reply, its very strange that I did exactly the same way as you suggested.Converted the type to date time but the results of absent is not coming correct.Below are the screenshots:-

 

created custom date as you created and made it date and it is duplicate of LastAttendancedate column

change1.JPG

Made the type as date  for calendar table date column

change2.JPG

Related calendar to student table with Date and custom column as shown below:-

change3.JPG

All the values are showing as both employees are absent:

change5.JPG

 

DAX measure used:-

forumlasused.JPG

But for your pbix file it is showing correctly.is there something I did incorrect or missing.Please provide your opinion

kind regards

sameer

Hi @deb_power123 ,

 

In the new column you create don't do the base of the last attendance and then formatting has date create a date column you can use one of the following code:

 

Date = Date(YEAR(Table[LastAttendace]), MONHT(Table[LastAttendace]), DAY(Table[LastAttendace]))

Date = Table[LastAttendace].[Date]

 

You can also create this column on the query editor using the syntax:

 

DateTime.Date ([LastAttendance])

 

Believe that when making the conversion is still keeping the hour in the background so the calculations are not returning correctly, don't really understand why.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thankyou so much for the guidance.I think I got the approach now.I was really struggling with this.

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.