Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Calculate average weekly active visitor using DAX

Visitor ID  DateVisit
15/10/2022  Visit 1      
25/10/2022Visit 1
35/10/2022Visit 1
15/10/2022Visit 2
55/10/2022Visit 1
25/10/2022Visit 2
15/11/2022Visit 1
65/11/2022Visit 1
95/11/2022Visit 1
105/12/2022Visit 1
115/12/2022Visit 1
125/13/2022Visit 1
25/16/2022Visit 1
25/16/2022Visit 2
135/18/2022Visit 1
145/18/2022Visit 1

 

Hello everyone,

 

I'm trying to calculate average weekly active visitors in PowerBI using DAX based on the example in the table above.

 

First, I need to calculate how many unique visitors visit the shop in one week (Mon-Sun). Based on the calendar, 5/10/2022 - 5/13/2022 will be categorized under one week, and 5/16/2022 - 5/18/2022 is another week. So for the week from 5/10/2022 - 5/13/2022, there are 9 unique visitor and for the week from 5/16/2022 - 5/18/2022, there are 3 unique visitors.

Once I found out the unique visitor for respective weeks, then I can get the average weekly active visitor by:

(9+3)/2 = 6 visitors

Hence, the answer for the example in the screenshot will be 6 visitors. The output will be used in card visualization.

 

Struggling to find the best way to do this, any help or advise will be greatly appreciated!

 

*Take note that Visit 1 means the first visit of the day while Visit 2 means the 2nd visit for the day.

1 ACCEPTED SOLUTION

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

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Thanks for your solution! As you mentioned, by using WEEKNUM, it will cause a problem if I have data for May 2023. Do you mean replace WEEKNUM by something else?

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

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Thanks for your edited answer! I think the latest measure solved my concern.

Jihwan_Kim
Super User
Super User

Hi,

Please check the below measure and the attached pbix file.

Please be noted that if your real data is showing not just one year, the year number calculation also has to be considered in the measure.

 

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

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.