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
j_w
Helper IV
Helper IV

How to get an average of partial data?

The demo table is like:

ID    UserCode    DefaultHours     TeamCode   Date               Hours

1      A                  5.0                       T1                  2017-05-31    4.5

2      B                  4.0                       T1                  2017-05-31    5.0

3      C                  2.0                       T2                  2017-05-31    2.5

4      A                  5.0                       T1                  2017-05-30    5.0

5      B                  4.0                       T1                  2017-05-30    4.0

6      A                  5.0                       T1                  2017-05-29    5.5

7      C                  2.0                       T2                  2017-05-29    2.0

8      D                  3.0                       T2                  2017-05-29    2.0

9      E                  6.0                        T1                  2017-05-29    2.0

NOTES: Different users in different days may have different Hours value, but eash user's DefaultHours is the same in all days.

 

How to create two new measures to get the two teams' average DefaultHours dynamically?

For example:

1). For the above 8 rows:

     Team T1's average DefaultHours should be (5+4+6)/3

     Team T2's average DefaultHours should be (2+3)/2

2). If Date 2017-05-29 was selected, then only 4 rows left:

     Team T1's average DefaultHours should be (5+6)/2

     Team T2's average DefaultHours should be (2+3)/2

 

Thanks

6 REPLIES 6
GilbertQ
Super User
Super User

Hi @j_w

 

You could possibly do the following measures below.

 

Total Default Hours = sum('TableName'[DefaultHours])

Total Rows = COUNTROWS('TableName')

Avg Default Hours = DIVIDE([Total Default Hours],[Total Rows])




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Hi @GilbertQ

 

Thanks for the reply.

 

Your method will get a different result, and is not working for team T1 and T2 respectively.

 

For example 1), the result from your method will be (5+4+...+3+6)/9 which is not equal to 

     Team T1's average DefaultHours should be (5+4+6)/3, or

     Team T2's average DefaultHours should be (2+3)/2

 

Hi @j_w

 

Based on your initial dataset there are 9 rows for T1?

 

Or did I miss something?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Hi @GilbertQ

 

ID 3, 7, 8 rows are under T2.

Hi @j_w

 

Yes that then looks correct for me if you look at the table and select T2 in the columns?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Hi @GilbertQ

 

I guess my question is not easy to catch 🙂

 

Go back to the dataset, the preferred values for following example:

1). For the above 9 rows:

     Team T1's average DefaultHours should be (A's DefaultHours+B's DefaultHours+E's DefaultHours)/(Count of T1 Users), which is (5+4+6)/3=5.0

     Team T2's average DefaultHours should be (C's DefaultHours+D's DefaultHours)/(Count of T2 Users), which is (2+3)/2=2.5

 

 

Your method:

1). For the above 9 rows:

     Team T1's average DefaultHours will be T1's total hours/rows, which is (5+4+5+4+5+6)/6=4.83

     Team T2's average DefaultHours will be T2's total hours/rows, which is (2+2+3)/3=2.33

 

Sorry about so many numbers in the above words, but hope I made it a little clearer.

 

Thanks

 

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.