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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
RogerSteinberg
Post Patron
Post Patron

Perform an average on a distinctcount after having used summarize

Hi,

 

I need to average out the past 2 months distinct count values.

 

Since my data is granular, I need to first calculate the distinctcount of users for the past 2 months and then perform the average on each month's value.

 

For example:

Columns: Month          DistinctCount        Previous2Months

Jan100-
feb50100
mar6972

 

 

 

 

VAR _distinctcount
SUMMARIZE(
    Query1,
    DateTable[YearMonthnumber],
    "distcount",DISTINCTCOUNT(Query1[User ID])
)
RETURN

 

 

 

Now how do I perform the average of the past 2 months only??????

1 ACCEPTED SOLUTION

Thanks but wanted to avoid the allselected function. and seems like the date range for the computation is not what I wanted.

 

I managed to make it work with this formula:

CALCULATE (
    AVERAGEX (
        SUMMARIZE (
            FactTable,
            DateTable[YearMonthnumber],
            "distinctC", DISTINCTCOUNT(FactTable[User ID])
        ),
        [distinctC]
    ),
    DATESINPERIOD (
        DateTable[Date],
        LASTDATE ( DATEADD(DateTable[Date],-1,MONTH )),
        -2,
        MONTH
    )
)

  

View solution in original post

4 REPLIES 4
dax
Community Support
Community Support

Hi @RogerSteinberg , 

You could refer to my sample for details.

Best Regards,
Zoe Zhi

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

Thanks but wanted to avoid the allselected function. and seems like the date range for the computation is not what I wanted.

 

I managed to make it work with this formula:

CALCULATE (
    AVERAGEX (
        SUMMARIZE (
            FactTable,
            DateTable[YearMonthnumber],
            "distinctC", DISTINCTCOUNT(FactTable[User ID])
        ),
        [distinctC]
    ),
    DATESINPERIOD (
        DateTable[Date],
        LASTDATE ( DATEADD(DateTable[Date],-1,MONTH )),
        -2,
        MONTH
    )
)

  

amitchandak
Super User
Super User

@RogerSteinberg , Try like

AverageX(
SUMMARIZE(
    Query1,
    DateTable[YearMonthnumber],
    "distcount",Rolling 12 = CALCULATE(DISTINCTCOUNT(Query1[User ID]),DATESINPERIOD(DateTable[Date],ENDOFMONTH(DateTable[Date]),-2,MONTH))  
),[distcount])
RETURN
Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Im not sure why but it gives me the same exact numbers as my 

Calculate ( DISTINCTCOUNT(user_id)) column. It doesn't filter for only the past two months.

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.