Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculate average weekly active visitor using DAX

Visitor ID   Date Visit 1 5/10/2022   Visit 1       2 5/10/2022 Visit 1 3 5/10/2022 Visit 1 1 5/10/2022 Visit 2 5 5/10/2022 Visit 1 2 5/10/2022 Visit 2 1 5/11/2...
  • Jihwan_Kim's avatar
    Jihwan_Kim
    4 years ago

    Hi,

    Thank you for your feedback.

    What i meant was, consider to insert one more condition that limits same-year-number into the measure.

    It depends on how you define year number and week number.

    Is it depends on ISO week number?

    What happens if year changes during the week?

     

    Just for simplifying the situation, I amended the measure a little bit.

    Please check the below amended measure.

    Based on your decision on how you define year number and week number, especially on the last week of the year or the first week of the year, the below measure has to be resived a little bit.

    But I think the below measure will work rest of the weeks during the year.

     

    I also fixed the measure in the attached pbix file.

     

     

    Expected outcome measure: =
    VAR currentyearnumber =
        YEAR ( TODAY () )
    VAR week_column =
        FILTER (
            SUMMARIZE (
                ADDCOLUMNS (
                    Data,
                    "@weeknumber", WEEKNUM ( Data[Date], 21 ),
                    "@yearnumber", YEAR ( Data[Date] )
                ),
                Data[Visitor ID],
                [@weeknumber],
                [@yearnumber]
            ),
            [@yearnumber] = currentyearnumber
        )
    VAR countID =
        GROUPBY (
            week_column,
            [@weeknumber],
            [@yearnumber],
            "@count", SUMX ( CURRENTGROUP (), 1 )
        )
    RETURN
        AVERAGEX ( countID, [@count] )