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
FPP
Frequent Visitor

Different Average - filtered items and total for a group not zero

I have the following table

DateKeyStatusAmount
Jan 1,2020A1open5
Jan 1,2020A1closed10
Jan 1,2020A1closed20
Jan 1,2020A2closed5
Jan 1,2020A2closed0
Jan 1,2020A3closed0
Jan 1,2020A4open40
Jan 1,2020A5closed50
Jan 1,2020A5closed-50
Jan 1,2020A5open30


I want the following:

numerator= SUM (Amount) where Status = 'closed' AND Amount <> 0 (Not a big deal to add the zero, since it doesn't change the SUM)
denominator= COUNT of DISTINCT(Key) where Status = 'closed' AND SUM(Amount grouped by the key) <> 0 
Ans: numerator/denominator

So for above:
numerator=10+20+5+0+50-50=35
denominator=2

Ans = 35/2 = 17.5

 

OR

numerator=10+20+5=35
denominator=2

Ans = 35/2 = 17.5

 

OR

numerator=30+5=35
denominator=2

Ans = 35/2 = 17.5

 

How can I do this in DAX?

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I think this should do the trick:

DifferentAverage =
CALCULATE (
    DIVIDE (
        SUM ( Table1[Amount] ),
        COUNTROWS (
            FILTER (
                SUMMARIZE ( Table1, Table1[Key], "KeySum", SUM ( Table1[Amount] ) ),
                [KeySum] <> 0
            )
        )
    ),
    Table1[Status] = "closed"
)

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

I think this should do the trick:

DifferentAverage =
CALCULATE (
    DIVIDE (
        SUM ( Table1[Amount] ),
        COUNTROWS (
            FILTER (
                SUMMARIZE ( Table1, Table1[Key], "KeySum", SUM ( Table1[Amount] ) ),
                [KeySum] <> 0
            )
        )
    ),
    Table1[Status] = "closed"
)

It worked.  Thank you!

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.