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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Redacted_VAR
Frequent Visitor

Weird Sum Error

Hi All,

 

very strange one, let me explain using the below example data,

i have a table much like the below:

AccountRevenue
Customer 1£100

Customer 2

£50
Customer 3£50
Customer 4£1
Customer 5£2

 

and i want to have a third column with a colour for whether the revenue is above or below the overall average (£40.60)

So i'm using the following formula for a measure (we'll call colour) i'm adding as a column to the table:

 

 

If(Sum(Table[Revenue])>Divide(Sum(Table[Revenue]),DistinctCount(Table[Account])),"Green","Red)

 

 

However that returns a table where all values above 0 are green:

AccountRevenueColour
Customer 1£100Green
Customer 2£50Green
Customer 3£50Green
Customer 4£1Green
Customer 5£2Green

 

However if i take the exact same code, but substitute the 2nd Sum function for the total number, it's then correct:

 

If(Sum(Table[Revenue])>Divide(203,DistinctCount(Table[Account])),"Green","Red)​

 

so that only leads me to believe the 2nd Sum function is for some reason returning 0. this is the same case for any measures that work in other cards, or if i set up the SUM function as it's own measure.

 

the table i should get is this:

 

AccountRevenueColour
Customer 1£100Green
Customer 2£50Green
Customer 3£50Green
Customer 4£1Red
Customer 5£2Red

 

so confused why the same logical function would return two different values.... help please?

 

1 ACCEPTED SOLUTION
IAmAPowerBIUser
Frequent Visitor

If I understood the purpose of your measure correctly you would have to remove row context to calculate your average Revenue to be able to use it in a table:

 

e.g.

 

Colour =

VAR TotalRevenue = CALCULATE(SUM('Table'[Revenue]), ALL('Table'))
VAR TotalCustomers = CALCULATE(DISTINCTCOUNT('Table'[Account]), ALL('Table'))
VAR AvgRevenuePerCustomer = DIVIDE(TotalRevenue, TotalCustomers)
VAR CurrentRevenue = SUM('Table'[Revenue])
RETURN
    IF(
        CurrentRevenue > AvgRevenuePerCustomer,
        "Green",
        "Red"
    )

 

 

IAmAPowerBIUser_0-1713898571550.png

 

View solution in original post

5 REPLIES 5
Redacted_VAR
Frequent Visitor

worked it out, if i wrapped the ALL() Table in a Filter() and reapplied then it worked. 

Redacted_VAR
Frequent Visitor

Hi @IAmAPowerBIUser ,

 

I notice that the All() function ignores my current page filters, which is a problem - how do i execute the above code whilst retaining my filters?

IAmAPowerBIUser
Frequent Visitor

If I understood the purpose of your measure correctly you would have to remove row context to calculate your average Revenue to be able to use it in a table:

 

e.g.

 

Colour =

VAR TotalRevenue = CALCULATE(SUM('Table'[Revenue]), ALL('Table'))
VAR TotalCustomers = CALCULATE(DISTINCTCOUNT('Table'[Account]), ALL('Table'))
VAR AvgRevenuePerCustomer = DIVIDE(TotalRevenue, TotalCustomers)
VAR CurrentRevenue = SUM('Table'[Revenue])
RETURN
    IF(
        CurrentRevenue > AvgRevenuePerCustomer,
        "Green",
        "Red"
    )

 

 

IAmAPowerBIUser_0-1713898571550.png

 

Redacted_VAR
Frequent Visitor

Hi @IAmAPowerBIUser ,

 

unfortunately not, as it contains sensitive information. I can answer any questions you might have however.

 

thanks

IAmAPowerBIUser
Frequent Visitor

Hi, would you mind to provide the corresponding  .pbix  file?

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.