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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply

How to calculate average time with condition in "New Measure" based on the date filter

Hi,

I need support. I need to calculate the average time of each process in new measure. But I need to set up a condition in the new measure. Unfortunately it did not work.

 

Below you will find the demo data. Process A, B and C have type full. In process D there are two different types. Avg should be for each type.
For example,

if process = D, then Calculate((sum of time for full/ count of process for full)+(sum of time for part/ count of process for part)) otherwise Calculate((sum of time/ count of process))

Note that: I used "calculate" because the average value could be changed based on the date filter.

 

 

ProcessTypeTimeDate
Afull2003.04.2024
Afull1804.04.2024
Afull1605.04.2024
Bfull1406.04.2024
Cfull1507.04.2024
Bfull1708.04.2024
Cfull1909.04.2024
Dpartial610.04.2024
Dfull1811.04.2024
Dpartial412.04.2024
Dfull1813.04.2024
Dfull2014.04.2024
    
    
1 ACCEPTED SOLUTION

You amy exclude exception from the average

Average =
CALCULATE (
    SUMX (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER ( 'Table', 'Table'[Type] <> "Exception" ),
                'Table'[Process],
                'Table'[Type]
            ),
            "@Average", DIVIDE ( [Sum by Type], [Count by Type] )
        ),
        [@Average]
    )
)

or from both the sum and count

Count by Type = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    ALLEXCEPT ( 'Table', 'Table'[Type], 'Table'[Process] ),
    FILTER ( 'Table', 'Table'[Type] <> "Exception" )
)
Sum by Type = 
CALCULATE (
    SUM ( 'Table'[Time] ),
    ALLEXCEPT ( 'Table', 'Table'[Type], 'Table'[Process] ),
    FILTER ( 'table', 'Table'[Type] <> "Exception" )
)

 

danextian_0-1716420095760.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4

Hi @danextian,
Thank you very much for your solution. I have tried your solution. Unfortunately, it showed me the wrong calculation with my real data.

Another information I share with you might help. There is exception in my data source. For this exception, the time value is empty. So we need to calculate the average without the exception.

 

 

ProcessTypeTimeDate
Afull2003.04.2024
Afull1804.04.2024
Afull1605.04.2024
Bfull1406.04.2024
Cfull1507.04.2024
Bfull1708.04.2024
Cfull1909.04.2024
Dpartial610.04.2024
Dfull1811.04.2024
Dpartial412.04.2024
Dfull1813.04.2024
Dfull2014.04.2024
CException 15.04.2024
DException 16.04.2024

 

Answer:

A18
B15,5
C17
D23,66667

 

 

danextian
Super User
Super User

Hi @ekramulmostaqui ,

 

Create these two measures first:

Sum by Type = 
CALCULATE ( SUM ( 'Table'[Time] ), ALLEXCEPT ( 'Table', 'Table'[Type], 'Table'[Process] ) )

Count by Type = 
CALCULATE ( COUNTROWS ( 'Table' ), ALLEXCEPT ( 'Table', 'Table'[Type], 'Table'[Process] ) )

 

Then this measure:

Average = 
SUMX (
    ADDCOLUMNS (
        SUMMARIZE ( 'Table', 'Table'[Process], 'Table'[Type] ),
        "@Average", DIVIDE ( [Sum by Type], [Count by Type] )
    ),
    [@Average]
)

danextian_0-1716379031917.png

 

 Please see attached sample pbix





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

You amy exclude exception from the average

Average =
CALCULATE (
    SUMX (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER ( 'Table', 'Table'[Type] <> "Exception" ),
                'Table'[Process],
                'Table'[Type]
            ),
            "@Average", DIVIDE ( [Sum by Type], [Count by Type] )
        ),
        [@Average]
    )
)

or from both the sum and count

Count by Type = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    ALLEXCEPT ( 'Table', 'Table'[Type], 'Table'[Process] ),
    FILTER ( 'Table', 'Table'[Type] <> "Exception" )
)
Sum by Type = 
CALCULATE (
    SUM ( 'Table'[Time] ),
    ALLEXCEPT ( 'Table', 'Table'[Type], 'Table'[Process] ),
    FILTER ( 'table', 'Table'[Type] <> "Exception" )
)

 

danextian_0-1716420095760.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thank you for your solution. It worked

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors