Forum Discussion
Calculate average weekly active visitor using DAX
- 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] )
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] )
Thanks for your edited answer! I think the latest measure solved my concern.