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
river-phillips
Frequent Visitor

Finding Average Number of Months based on Quantity per Month

Hi all,

 

I'm attempting to display the average MonthsInSystem for each age group based on the quantity per MonthsInSystem. For example, take the following table:

 

AgeActualMonthsInSystemValue
12029
121114
12278
12324
1242
12534
12657
12765
12852
12949
121042
121170
121280
121335
121436
121536
121628
121722
121825
121930
122011
12218
122212
122315
122435
12257
122613
12275
12297
12302
12312
12324
Average Months in System? 


I want to definitively say '
For Age 12, the average number of months in system is X' but my average is currently only accounting for the MonthsInSystem (0-32) without the quantity per MonthsInSystem.

 

Any help with this will be appreciated!

1 ACCEPTED SOLUTION

Hi @river-phillips ,

Since you have a [TotalStudentMonth] measure, you can try this measure:

 

Average = 
VAR _sum =
    CALCULATE (
        [TotalStdentMonths],
        ALLEXCEPT ( 'Table', 'Table'[AgeActual], 'Table'[UserId] )
    )
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[UserId] ),
        ALLEXCEPT ( 'Table', 'Table'[AgeActual] )
    )
RETURN
    DIVIDE ( _sum, _count, BLANK () )

 

average.png

Please refer this sample file: average.pbix

 

Best Regards,
Yingjie Li

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

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@river-phillips , Not very clear. see if this can help

divide(sum(Table[Value]),sum(Table[MonthsInSystem]))

Hi @amitchandak thanks for the quick reply but that didn't work unfortunately.

 

Let me clarify a couple more things:

 

The "Values" column is actually a distinct count of users that fall within the AgeActual and MonthsInSystem category.

 

If I create a bar chart with the distinct students on the y axis and their total months in system on the x axis, the automatic 'average' line shows the correct value (see below). I'd like to create a measure/calculated column that displays the same value as shown in the bar chart.

 

averagemonthsinsystem.PNG

 

Thank you

Hi @river-phillips ,

To calculate the average of monthlnsystem for each ageactual, you can create this measure:

Average = 
VAR _monthlnsystem =
    CALCULATE (
        SUM ( 'Table'[MonthlnSystem] ),
        ALLEXCEPT ( 'Table', 'Table'[AgeActual] )
    )
VAR _countuser =
    CALCULATE ( COUNTROWS ( 'Table' ), ALLEXCEPT ( 'Table', 'Table'[AgeActual] ) )
RETURN
    DIVIDE ( _monthlnsystem, _countuser, BLANK () )

average.png

 

Attached the sample file that hopes to help you: Finding Average Number of Months based on Quantity per Month.pbix

 

Best Regards,
Yingjie Li

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

Hi @v-yingjl ,

 

Thank you for the reply. It definitely put me in the right direction, but it's still pulling the incorrect average Your provided measure is the last column, "Average". I was able to create a measure that calculated total number of months for an age group (TotalStudentMonths), but I'm unable to divide the measure's sum by the total DistinctCount of UserID for that age group (see below)

 

river-phillips_0-1597257360785.png

I have the right numbers: 737 for DistinctCount of UserID and 3936 for the total student months. These would give the correct average (3916 / 737 = 5.313) but I cannot figure out how to divide the Sum of TotalStudentMonths measure by the Sum of all distinct UserIDs for the age group. Any additional help will be appreciated!

 

Hi @river-phillips ,

Since you have a [TotalStudentMonth] measure, you can try this measure:

 

Average = 
VAR _sum =
    CALCULATE (
        [TotalStdentMonths],
        ALLEXCEPT ( 'Table', 'Table'[AgeActual], 'Table'[UserId] )
    )
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[UserId] ),
        ALLEXCEPT ( 'Table', 'Table'[AgeActual] )
    )
RETURN
    DIVIDE ( _sum, _count, BLANK () )

 

average.png

Please refer this sample file: average.pbix

 

Best Regards,
Yingjie Li

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

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.