Forum Discussion

HiltonS's avatar
HiltonS
Frequent Visitor
9 years ago

More than once a week

Hi Guys

 

I am currently working with attendance data of school learners. I would like to use a measure to calculate how many learners have attended more than once in a week across all weeks to date. I have a learner table, with unique learner number and date columns.

 

Hope you guys can help. 

 

Thanks

5 Replies

  • Hi HiltonS

     

    This can definitely be done.

     

    Just clarifying, do you want to calculate:

    1. The number of learners who have attended more than once in at least one week among all weeks to date?
    2. The number of learners who have attended more than once in every week to date?

    Owen

    • HiltonS's avatar
      HiltonS
      Frequent Visitor

      Thanks for the reply. More than once every week.

      • OwenAuger's avatar
        OwenAuger
        Icon for Super User rankSuper User

        HiltonS

         

        Here is a prototype.

         

        Suggested tables to make this work (Table: Columns):

        1. Learner: Learner
        2. Date: Date, Year-Week (or any sequential week column), End of Week flag (true/false, indicating whether a given date is the last day of a week)
        3. Attendance: Learner, Date

         

        Below is the measure I wrote to return the number of Learners who have attended more than once in every week so far.

        To summarise what the measure is doing:

        1. It works out which weeks have completely passed so far using a series of variables, and stores the result in the variable WeeksUpToMaxCompleteWeek. (If you only filter on whole weeks, then this whole calculation may be unnecessary.)
        2. Then, in the section following RETURN, it takes the selected Learners and removes those who have had fewer than 2 attendances in any of these weeks.
        3. Then it counts these Learners using COUNTROWS.

         

         

        Number of Learners With More Than 1 attendance in all weeks to date = 
        VAR ValuesLearners =
            VALUES ( Learner[Learner] )
        VAR DatesUpToMaxDate =
            DATESBETWEEN ( 'Date'[Date], BLANK (), MAX ( 'Date'[Date] ) )
        VAR MaxEndOfWeekDate =
            CALCULATE ( MAX ( 'Date'[Date] ), 'Date'[Last Day of Week], DatesUpToMaxDate )
        VAR DatesUpToMaxCompleteWeek =
            DATESBETWEEN ( 'Date'[Date], BLANK (), MaxEndOfWeekDate )
        VAR WeeksUpToMaxCompleteWeek =
            CALCULATETABLE ( VALUES ( 'Date'[Year-Week] ), DatesUpToMaxCompleteWeek )
        RETURN
            CALCULATE (
                COUNTROWS (
                    EXCEPT (
                        ValuesLearners,
                        SELECTCOLUMNS (
                            GENERATE (
                                WeeksUpToMaxCompleteWeek,
                                FILTER ( ValuesLearners, CALCULATE ( COUNTROWS ( Attendance ) ) < 2 )
                            ),
                            "Learner", Learner[Learner]
                        )
                    )
                ),
                DatesUpToMaxCompleteWeek
            )

         

        Anyway, I guess this will need adapting to your model.

         

        Regards,

        Owen