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

Average of distinctcount over

Hi!

 

I'm trying to create an average of unique values (user ID) over a 12 month period.

 

Every user logs a couple of entries every month so to get the monthly value i do a distinctcount. 

 

Jan: 800

Feb: 900

Mar: 950

Apr: 1000

May: 1050

 

I want to return the average of these and be able to use it in a rolling twelve, so for the data above i expect:

(R3 to save space)

Mar: 883,3

Apr: 950

May: 1000

 

 

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

You can follow below steps to create a calcualte column to show the dynamic average.

 

1. Convert Month column to date as index.

Date = DATEVALUE([Month]&"/1") 

 

2.  Use date column to calculate the rolling average.

Dynamic Average = AVERAGEX(FILTER(ALL('Table'),[Date]<=EARLIER('Table'[Date])),[Amount]) 

 

3.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Sorry I wasn't very clear on my data or case. 

 

I've got a date table that translates periods to date

and a records table where each emplyee i stamped on periods.  (400 000 rows, 3000 uniqe employees, 8 years of data)

 

timeaccperiodDate
2017312017-08-06
2017322017-08-13
2017332017-08-20
2017342017-08-27
2017352017-09-31
2017362017-09-07
2017372017-09-14
2017382017-09-21
2017392017-09-28

 

employeetimeaccperiod
AA201731
BB201731
AA201732
BB201732
AA201733
BB201733
AA201734
AA201735
AA201736
AA201737
AA201738
AA201739

 

Now i can do a distinctcount to get 

2017-08 = 2 (AA&BB)

2017-09 = 1 (AA)

 

But I can't get an rolling twelve average

I want to be able to plot it in a matrix/graph like this

 

jan-17feb-17mar-17apr-17maj-17jun-17jul-17aug-17sep-17
820827834841848855862869876

 

 

Where sept-17 is the average uniqe number of employees per month okt-16 to sept-17.

 

Durring any month there's 800-900 uniqe employees but since employees are coming and going the total unique employees over 12 months is more like 1200. 

(i then want to divide this by another value, but I don't think that's relevant. )

Ashish_Mathur
Super User
Super User

Hi,

 

Hoe did you get to those answers from the data that you shared.  Please share a complete example with the answer you are expecting on that dataset.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
CahabaData
Memorable Member
Memorable Member

Because in your post you do not display a year value ; I just want to point out that this is needed and that your column is set as a date column, not text. 

 

So assuming your date column is Year Month date - here is some air code for a measure that should work for step 1 which is to establish the Year to Date sum:

 

YTD =

VAR

RowDate = CALCULATE( MAX( 'Table'[Yearmonth] ) )

RETURN    

 

  CALCULATE(  SUM ( 'Table'[ValueColumn] ),       

        FILTER(  ALLSELECTED( 'Table' ),           

          'Table'[Yearmonth] <= RowDate  && YEAR( 'Table'[Yearmonth] ) = YEAR( RowDate ) ) )

 

Once you have this YTD step 1, then you can create a new measure that divides the YTD measure by 12 - or modify the YTD measure itself to include that division also if you prefer.

 

 

www.CahabaData.com

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.