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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Rebender
Frequent Visitor

Calculate Average with Filter

Good afternoon,

I am trying to create an average using a filter.  In my screen shot below, you can see that under the Attribute column there are two different values.  I want to be able to sum up the Process Hours Entry to 1CR column and divide it by the count of the Attribute column where the value is 1CR_Associate_ID.  Currently when I try and just use the average function it is dividing the total by 16.  Any ideas on how to accomplish this???  Thanks in Advance!!

 

Renee

 

Datatable.png

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

HI, @Rebender

You may try to this formula to create a measure as below:

Measure = 
DIVIDE (
    CALCULATE ( SUM ( 'Table'[Process Hours Entry to] ) ),
    CALCULATE (
        COUNTA ( 'Table'[Attribute] ),
        'Table'[Process Hours Entry to] <> 0
    ),
    0
)

or use this formula to create a column

Column = DIVIDE (
    CALCULATE ( SUM ( 'Table'[Process Hours Entry to] ),FILTER('Table','Table'[Attribute]=EARLIER('Table'[Attribute]) )),
    CALCULATE (
        COUNTA ( 'Table'[Attribute] ),FILTER('Table','Table'[Attribute]=EARLIER('Table'[Attribute])&&
        'Table'[Process Hours Entry to] <> 0)
    ),
    0
)

Result:

measuremeasurecolumncolumn

here is pbix, please try it.

https://www.dropbox.com/s/rgvy7m8w1l15we6/Calculate%20Average%20with%20Filter.pbix?dl=0

 

Best Regards,

Lin

 

 

 

 

Community Support Team _ Lin
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

10 REPLIES 10
blodus
Advocate II
Advocate II

Is there anything in Power BI that isn't ridiculously difficult to do? 

v-lili6-msft
Community Support
Community Support

HI, @Rebender

You may try to this formula to create a measure as below:

Measure = 
DIVIDE (
    CALCULATE ( SUM ( 'Table'[Process Hours Entry to] ) ),
    CALCULATE (
        COUNTA ( 'Table'[Attribute] ),
        'Table'[Process Hours Entry to] <> 0
    ),
    0
)

or use this formula to create a column

Column = DIVIDE (
    CALCULATE ( SUM ( 'Table'[Process Hours Entry to] ),FILTER('Table','Table'[Attribute]=EARLIER('Table'[Attribute]) )),
    CALCULATE (
        COUNTA ( 'Table'[Attribute] ),FILTER('Table','Table'[Attribute]=EARLIER('Table'[Attribute])&&
        'Table'[Process Hours Entry to] <> 0)
    ),
    0
)

Result:

measuremeasurecolumncolumn

here is pbix, please try it.

https://www.dropbox.com/s/rgvy7m8w1l15we6/Calculate%20Average%20with%20Filter.pbix?dl=0

 

Best Regards,

Lin

 

 

 

 

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

Thank you so much for your help!  I have just one more question....  How would I change the code if I want to have this divide by a distinct count of WPS?  I have two rows that have the same number so I would like to sum the 4 rows hours and then divide by a distinct count of WPS (3)...

 

Thanks again!

Renee

Helle @Rebender,

 

Try this;

Measure2 = 
DIVIDE (
    CALCULATE ( SUM ( 'Table'[Process Hours Entry to] ) );
    CALCULATE (
        DISTINCTCOUNT( ( 'Table'[WPS] ));
        'Table'[Process Hours Entry to] <> 0
    );
    0
)

Greets,

 

Ronald

This is working great except I have one more question/problem.....  I have slicers on my report that the measure seems to be ignoring.   Do I have to do something else in order for the measure to use the slicers?

 

thanks again!!!

Renee

hi, @Rebender

You should check these slicers if had created the relationship with this table and the cross filter direction if is both.

otherwise it should can be affected by slicer.

 

Best Regards,

Lin

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

Hello @Rebender,

 

If the date field in the slicer is from an another table, you must make a connection between the differt tables.
Otherwise, you must give more information because a slicer with a data field from the table of your'e measures must work,

 

Greets,

 

Ronald

 

Ronald123
Resolver III
Resolver III

Hello @Rebender,

 

Try this;

AverageFilter = DIVIDE(
SUM(Table1[1CR]);
    CALCULATE(    
    COUNT(Table1[Attribute]);
    Table1[Attribute]="1CR_Associate_ID"))

Greets,

 

Ronald

Greg_Deckler
Super User
Super User

Perhaps something along the lines of:

 

Measure = 
VAR __attribute = MAX('Table'[Attribute])
RETURN AVERAGEX(FILTER('Table',[Attribute]=__attribute),[1CR])

Put in table visual along with Attribute.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for you assistance!  Any idea why the value calculates out to 8.17?  If I add the numbers and divide by 4 I come up with 7.81....

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors