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
LS-PScience
Regular Visitor

Measure - how to sum value over a week (for players) and then average this based on category

Hi guys, first time posting so please forgive me if I'm not very clear!

Dummy data and issue shown below.

Date

WK Start Date

Player

CategoryValue
28/09/202125/09/2021A12000
28/09/202125/09/2021B15000
27/09/202125/09/2021A13000
27/09/202125/09/2021B14000

 

So first I want a measure to SUM the week (based on week start date) e.g. expected result for Player A is a sum of 5000 for week beginning on the 25th. Then I want a measure for the Category AVERAGE for that week e.g. expected result is players Bs sum being 9000 for the same week, so the average for Category 1 would be 7000. The full data set will include multiple rows of data over many dates and week start dates, and each player will have an assigned category.

Any ideas on what the Dax measures (not columns) would look like for these measures?

Thanks in advance!

Logan

1 ACCEPTED SOLUTION
colacan
Resolver II
Resolver II

@LS-PScience Hi LS-PScience,

Please try belwo two measures.

SumByWkByPlayer =
CALCULATE(sum(sumvalueweek[Value]),
    ALLEXCEPT(sumvalueweek,sumvalueweek[WK Start Date],sumvalueweek[Player])
)

 

CategoryAvg =

CALCULATE(
   AVERAGEX(
        ADDCOLUMNS(
            SUMMARIZE( sumvalueweek, sumvalueweek[Player], sumvalueweek[WK Start Date] ),
           "sumvalue", CALCULATE( SUM( sumvalueweek[Value] ) )
            ),
           [sumvalue]
        ),
  REMOVEFILTERS( sumvalueweek[Date] )
)
 
colacan_0-1632835732373.png

 

Hope this helps you.
 
Please mark it as the solution if it helped you.

View solution in original post

3 REPLIES 3
colacan
Resolver II
Resolver II

@LS-PScience Hi LS-PScience,

Please try belwo two measures.

SumByWkByPlayer =
CALCULATE(sum(sumvalueweek[Value]),
    ALLEXCEPT(sumvalueweek,sumvalueweek[WK Start Date],sumvalueweek[Player])
)

 

CategoryAvg =

CALCULATE(
   AVERAGEX(
        ADDCOLUMNS(
            SUMMARIZE( sumvalueweek, sumvalueweek[Player], sumvalueweek[WK Start Date] ),
           "sumvalue", CALCULATE( SUM( sumvalueweek[Value] ) )
            ),
           [sumvalue]
        ),
  REMOVEFILTERS( sumvalueweek[Date] )
)
 
colacan_0-1632835732373.png

 

Hope this helps you.
 
Please mark it as the solution if it helped you.
VahidDM
Super User
Super User

Hi @LS-PScience 

 

Please try these measures:

Sum Week:

Sum Week = 
VAR _Week =
    MAX ( 'Table'[WK Start Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        ALLEXCEPT ( 'Table', 'Table'[WK Start Date], 'Table'[Player] )
    )

 

Average:

Average = 
VAR _SumCat =
    CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Category] ) )
VAR _CountPlayer =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Player] ),
        ALLEXCEPT ( 'Table', 'Table'[Category] )
    )
RETURN
    _SumCat / _CountPlayer

 

Output:

 

VahidDM_0-1632786739953.png

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos🙏!!

Hey VahidDM

I've replicated your measures but it didn't quite work as I'd hoped unfortunately.

It appears that with more than 1 week start dates (or maybe its the multiple categories messing it up), it would just sum everything rather than average. Are you able to check with the following data and see if your measures still work for you?

Date

WK Start Date

Player

CategoryValue
28/09/202125/09/2021A12000
28/09/202125/09/2021B15000
28/09/202125/09/2021C26000
28/09/202125/09/2021D21500
27/09/202125/09/2021A13000
27/09/202125/09/2021B14000
27/09/202125/09/2021C21000
27/09/202125/09/2021D23500
23/09/202118/09/2021A14500
23/09/202118/09/2021B15000
23/09/202118/09/2021C25000
23/09/202118/09/2021D29000
19/09/202118/09/2021A17000
19/09/202118/09/2021B15000
19/09/202118/09/2021C22000
19/09/202118/09/2021D22500

 

Thankyou!

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