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

Sum the unique values and average repeating values for duplicated Purchase orders

Hello,

 

I have been struggling with this and cannot find a solution online. My data has PO numbers and values that is linked to Jobs. As a result the PO numbers will repeat for every job linked to it. In most cases the repeating PO number has on assigned value so an average formula will correctly summarize the values. The problem is that when the values are not the same, then the average formula does not work.

 

The fomula I am using is 

PO FEE-Euro =
SUMX (
    VALUES ( 'Country Submissions'[PO fee Value-Euro] ),
    CALCULATE ( AVERAGE ( 'Country Submissions'[PO fee Value-Euro]) )
)

 

however PO ABCD total should be 278,375 but the formula averages the 68,250 rather than sum. I need a way that when a PO repeates and the PO value is the same to average the values but if a PO reapeats and the values are unique to sum. The results should be the sum of the avergae of repeating values attached to a repeating PO + the sum of unique values attched to a repeating PO. Thank you in advance. Below is an example of the data.

 

Local Job NumberJob Description (Job Title)Client PO numberClient PO Fee amountClient PO OOP amount
233714Job 1ABCD48,225.0062,500.00
233715Job 2ABCD11,325.00-
233716Job 3ABCD68,250.0015,416.67
233717Job 4ABCD68,250.0015,416.67
233718Job 5ABCD45,365.0083,333.33
233623Job 6ABCD36,960.00-
223360Job 21MNOP66,000.00-
223360Job 22MNOP51,500.00-
223361Job 23MNOP51,500.0012,857.14
223361Job 24MNOP51,500.0012,857.14
223362Job 25MNOP51,500.00-
223362Job 26MNOP38,629.00-
223363Job 27MNOP61,815.0071,428.57
223363Job 28MNOP68,810.00-
223365Job 29MNOP44,709.00-
223359Job 30MNOP48,940.00-
223365Job 31QRST48,740.00-
223366Job 32QRST46,946.00-
223359Job 33QRST57,490.0025,000.00
223368Job 34QRST10,638.0021,428.57
223364Job 35QRST26,460.60-
223367Job 36QRST41,430.00-
223248Job 37QRST25,625.00-
223248Job 38QRST14,125.00-
223248Job 39QRST15,250.00-
223248Job 40QRST25,275.00-
223248Job 41QRST14,800.00-
1 ACCEPTED SOLUTION

Try this, a little simpler

 

PO FEE-Euro =
SUMX(
SUMMARIZE(
'Country Submissions',
'Country Submissions'[Client PO number],
"AvgOrSum",
IF(
COUNTROWS(
FILTER(
'Country Submissions',
'Country Submissions'[Client PO number] = EARLIER('Country Submissions'[Client PO number]) &&
'Country Submissions'[Client PO Fee amount] <> EARLIER('Country Submissions'[Client PO Fee amount])
)
) > 0,
SUM('Country Submissions'[Client PO Fee amount]),
AVERAGE('Country Submissions'[Client PO Fee amount])
)
),
[AvgOrSum]
)

View solution in original post

6 REPLIES 6
devindupree01
Helper I
Helper I

Hey Lynn,

 

Maybe over complicated but the Logic should be more like this

 

PO FEE-Euro =
VAR UniquePOs = SUMMARIZE('Country Submissions', 'Country Submissions'[Client PO number])
VAR Result =
SUMX(
UniquePOs,
VAR CurrentPONumber = [Client PO number]
VAR RelevantRows =
FILTER(
'Country Submissions',
'Country Submissions'[Client PO number] = CurrentPONumber
)
VAR UniqueValues = VALUES(RelevantRows[Client PO Fee amount])
RETURN
SUMX(
UniqueValues,
VAR CurrentValue = [Client PO Fee amount]
VAR CountOfCurrentValue =
CALCULATE(
COUNTROWS(RelevantRows),
RelevantRows[Client PO Fee amount] = CurrentValue
)
RETURN
IF(
CountOfCurrentValue > 1,
CurrentValue,
CurrentValue * CountOfCurrentValue
)
)
)
RETURN Result

 

 

If this helped, please mark as solved! 🙂

I added the formula bu am getting the below formula error

LynnM_0-1691002108633.png

 

Try this, a little simpler

 

PO FEE-Euro =
SUMX(
SUMMARIZE(
'Country Submissions',
'Country Submissions'[Client PO number],
"AvgOrSum",
IF(
COUNTROWS(
FILTER(
'Country Submissions',
'Country Submissions'[Client PO number] = EARLIER('Country Submissions'[Client PO number]) &&
'Country Submissions'[Client PO Fee amount] <> EARLIER('Country Submissions'[Client PO Fee amount])
)
) > 0,
SUM('Country Submissions'[Client PO Fee amount]),
AVERAGE('Country Submissions'[Client PO Fee amount])
)
),
[AvgOrSum]
)

THANK YOU!!!!! This worked. I cannot tell you how many hours my team and I worked trying to figure this out. You have been heaven sent!

Mkarwa-123
Resolver II
Resolver II

@LynnM because you have average function inside calclculate.

How do I correct? I am not great with formulas. Thanks

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.