Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

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

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    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]
            )
        )

     

     

     

    • Anonymous's avatar
      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

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

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

  • mahoneypat's avatar
    mahoneypat
    Microsoft 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

    • Anonymous's avatar
      Anonymous
      Not applicable

      mahoneypat ,

       

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

       

      Best,

      LA