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
Anonymous
Not applicable

DAX Help for measure

Hi,

 

I do not know how to create the DAX for direct measure of the total number ChildID who has absent 3 or more consecutive days. Maybe there is any simple DAX to measure this?

Please help me to do this and thank you for your help.

 

I am sorry for the tag, but please help me find out DAX to measure:
@harshnathani @darlove  @Greg_Deckler  @mahoneypat @camargos88 @amitchandak 

@vivran22 @bboobe @LAndes  @AlB  @Pragati11  @parry2k @az38  @edhans  

 

Here, I am attached the data on this link:

My Data 

7 REPLIES 7
mahoneypat
Employee
Employee

I'm sure there is a more efficient/elegant way to do this, but I ran out of time on my lunch break.  This expression gets the right result of 1 for the sample dataset provided.

 

Kids with 3+ Consecutive Days Absent =
VAR summarytable =
ADDCOLUMNS (
SUMMARIZE ( Attendance, Attendance[ChildID], Attendance[AttendanceDate] ),
"inarow", CALCULATE (
VAR thisdate =
SELECTEDVALUE ( Attendance[AttendanceDate] )
VAR falselast3days =
CALCULATE (
COUNT ( Attendance[ChildID] ),
ALLEXCEPT ( Attendance, Attendance[ChildID] ),
Attendance[AttendanceDate] <= thisdate,
Attendance[AttendanceDate] >= thisdate - 2,
Attendance[IsPresent?] = FALSE ()
)
RETURN
falselast3days
)
)
RETURN
CALCULATE (
DISTINCTCOUNT ( Attendance[ChildID] ),
FILTER ( summarytable, [inarow] = 3 )
)

 

Your dates were all consecutive, so this works.  I suspect you are going to need to exclude non-school days, but you can adapt this approach.

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat ,

 

I have not running that DAX because DAX running to slow. Please share pbix file on attachment.

 

Best,

LA

Greg_Deckler
Super User
Super User

@Anonymous - I did it this way, (PBIX attached after sig)

Created this column:

Absent = 
    VAR __Last = MAXX(FILTER('AttendanceMaster',[ChildID] = EARLIER([ChildID]) && [AttendanceDate] < EARLIER([AttendanceDate])),[AttendanceDate])
    VAR __Min = MINX(FILTER('AttendanceMaster',[ChildID] = EARLIER([ChildID])),[AttendanceDate])
RETURN
    IF([AttendanceDate] = __Min,0,([AttendanceDate] - __Last) * 1.)

And then this measure:

Measure = 
    COUNTROWS(
        SUMMARIZE(
            FILTER('AttendanceMaster',[Absent] >= 3),
            [ChildID]
        )
    )

 

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler ,

 

Thank you for the DAX Formula,

 

I think this DAX not measured total ChildID who has FALSE 3+ days on column IsPresent.

For example, please look at the table below:

 

ChildIDAttendanceDateIsPresent?
113 February 2020FALSE
114 February 2020FALSE
115 February 2020FALSE
116 February 2020FALSE
223 February 2020TRUE
224 February 2020FALSE
225 February 2020FALSE
226 February 2020TRUE

 

Based on the table, we know that there is 1 ChildID was absent for 4 consecutive days, the ChildID is 11.

 

I am sorry to make you busy.

 

Thank you

@Anonymous - Sorry, missed the IsPresent field and was just going by AttendanceDate. Clearly misunderstood the data. Will take another look.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Anonymous  - Went back to my EARLIER approach (sorry bad joke) and implemented Cthulhu. PBIX is attached.

Absent = 
    VAR __index = CALCULATE(MAX([AttendanceDate]))
    VAR __group = CALCULATE(MAX([ChildID]))
    VAR __tmpTable1 = FILTER(ALL('AttendanceMaster'),[ChildID]=__group && [IsPresent] = FALSE() && [AttendanceDate]<__index)
    VAR __tmpTable2 = ADDCOLUMNS(__tmpTable1,"__diff",[AttendanceDate] - MAXX(FILTER(ALL('AttendanceMaster'), [IsPresent] = FALSE() && [AttendanceDate] < EARLIER([AttendanceDate]) && [ChildID]=EARLIER([ChildID])),[AttendanceDate])) 
    VAR __max = MAXX(__tmpTable2,[AttendanceDate])
    VAR __maxStart = MAXX(FILTER(__tmpTable2,[__diff]>1),[AttendanceDate])
    VAR __tmpTable3 = FILTER(__tmpTable2,[AttendanceDate]>=__maxStart)
RETURN 
    IF(ISBLANK(__max),1,IF(__max=__index-1,COUNTROWS(__tmpTable3)+1,1))

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler ,

Thank you.

I found this DAX works well but there is a little joke from you when I have looked at Absent Column on Data Table.  We know that If Column IsPresent is TRUE than Column Absent will be 0.

DAX that you have created is very simple and I understand your approach and I think this a very cool way.

 

@mahoneypat ,

 

Thanks,

I will be looking for your approach now.

 

Best

LA

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.