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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Average of Measure

Hi, 

In my historical project table I have created the following measure:

TimeSinceModification =
VAR _CurrentDate = TODAY()

VAR _LastIdModification =
    CALCULATE(
            MAX(Audit[ModifiedOn].[Date]),
            FILTER(
                ALLSELECTED(Audit),
                Audit[Id] = MAX(Audit[Id])))

VAR _TimeSinceLastModification =
    DATEDIFF(_LastIdModification,_CurrentDate,DAY)

RETURN
   _TimeSinceLastModification


The measure is showing number of days since the last modification for each project in the table. 
Now I have to create an measure showing the average number of days since last modification. I tried different AverageX,Sumx e.g.
But everytime it is summing incorrect. Doe's anyone have an idea how to solve this problem?
@SpartaBI 


1 ACCEPTED SOLUTION

Hi,

Thank you for your message, and please check the below picture and the attached pbix file whether it suits your requirement.

 

Picture1.png

 

Expected avg measure: =
VAR _maxdatebyIDtable =
    CALCULATETABLE (
        Data,
        TREATAS (
            GROUPBY (
                Data,
                Data[ID],
                "@maxdate", MAXX ( CURRENTGROUP (), Data[Name ModifiedOn] )
            ),
            Data[ID],
            Data[Name ModifiedOn]
        )
    )
RETURN
    DIVIDE (
        SUMX ( _maxdatebyIDtable, Data[Days since modification] ),
        COUNTROWS ( _maxdatebyIDtable )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your dataset looks like, but please try something like below and check whether it works for your dataset.

 

expected measure: =
AVERAGEX (
    ADDCOLUMNS (
        VALUES ( 'projecttable'[projectID] ),
        "@datediff", [TimeSinceModification]
    ),
    [@datediff]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi Jihwan,

I have tried to replicate the structure of my data tabel and hope it gives better meaning now:

NikFe_0-1660648414615.png

E.g. you can see that I have filtered 6 unique project. But project 260 have 2 different modification date and it should only calculate the Lates modified. 
So here the correct Average should be (roundet) 5

Hi,

Thank you for your message, and please check the below picture and the attached pbix file whether it suits your requirement.

 

Picture1.png

 

Expected avg measure: =
VAR _maxdatebyIDtable =
    CALCULATETABLE (
        Data,
        TREATAS (
            GROUPBY (
                Data,
                Data[ID],
                "@maxdate", MAXX ( CURRENTGROUP (), Data[Name ModifiedOn] )
            ),
            Data[ID],
            Data[Name ModifiedOn]
        )
    )
RETURN
    DIVIDE (
        SUMX ( _maxdatebyIDtable, Data[Days since modification] ),
        COUNTROWS ( _maxdatebyIDtable )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi, 

I have implemented your solution and it works perfectly.

Thanks

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.