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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Rolling average of a measure using DISTINCTCOUNT

Hi all,

 

So I have a typical sales data table with columns containing Date, CustomerName, ProductCode, Qty, Price etc.

 

I am analysing the number of unique customers ordering from us per week, and have a measure using:

 

DistinctCustomers = DISTINCTCOUNT(CustomerName)

 

which I have plotted over time (see below) and this works fine.  

 

CustomerCount.jpg

 

However I also want to include a 13 week (91 day) rolling average to smooth out the peaks and troughs and assess the general trend. I tried the usual

 

CALCULATE(DistinctCustomers, DATESINPERIOD(Date, LASTDATE(Date), -91, DAY)

 

Divided by 13 to get the 13 week average. However the above seems to calculate the number of unique customers within the 13 week period, not the sum of the unique customers in each week. I guess I could create a measure containing 13 individual CALCULATE statements, one for each week of the rolling average, sum them and divide by 13 but I can't believe that is the most elegant DAX solution.

 

Anyone out there already have a solution to rolling average of a DISTINCTCOUNT measure? Any help or suggestions gratefully received.

 

Cheers,

 

Michael.

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

Maybe this is what you are looking for:

SUMX(
    DATESINPERIOD(Date, LASTDATE(Date), -91, DAY)
    ,[DistinctCustomers]
)
/13 

Hopefully this provides what you are looking for.

 

If not - you might consider to provide an Excel file with some sample data, upload the file to onedrive or dropbox and share the link. This provides the possiblity to make up your expected result and also avoids misunderstandings.

 

Regards,

Tom

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey,

 

Maybe this is what you are looking for:

SUMX(
    DATESINPERIOD(Date, LASTDATE(Date), -91, DAY)
    ,[DistinctCustomers]
)
/13 

Hopefully this provides what you are looking for.

 

If not - you might consider to provide an Excel file with some sample data, upload the file to onedrive or dropbox and share the link. This provides the possiblity to make up your expected result and also avoids misunderstandings.

 

Regards,

Tom

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Your a genius, many thanks Tom, that is working perfectly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors