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

Create a measure that Averages if a category = Contract Price or sum if a category = Costs

I want to return sum of value if category = Costs and average if Category = Contract Price. Below is what I have tried but no luck.

My Columns are Category and Value.

Total = 
SWITCH(SELECTEDVALUE('P&L Baseline'[Category],"Contract Price ($/Ton)", AVERAGEX(FILTER('P&L Baseline','P&L Baseline'[Category] = "Contract Price ($/Ton)"),'P&L Baseline'[Value]),"Costs($)",SUMX(FILTER('P&L Baseline','P&L Baseline'[Category] = "Costs($)"), 'P&L Baseline'[Value]))


 

1 ACCEPTED SOLUTION

hi @CJ0323 

 

try like:

Total = 

SWITCH(

    SELECTEDVALUE('P&L Baseline'[Category]),

    "Contract Price ($/Ton)", AVERAGEX(FILTER(ALL('P&L Baseline'),'P&L Baseline'[Category] = "Contract Price ($/Ton)"),'P&L Baseline'[Value]),

    "Costs($)",

    SUMX(FILTER(ALL('P&L Baseline'),'P&L Baseline'[Category] = "Costs($)"), 'P&L Baseline'[Value])

)

View solution in original post

4 REPLIES 4
FreemanZ
Super User
Super User

hi @CJ0323 

try like:

Total = 
SWITCH(
    SELECTEDVALUE('P&L Baseline'[Category],
    "Contract Price ($/Ton)",     AVERAGEX(FILTER(ALL('P&L Baseline'),'P&L Baseline'[Category] = "Contract Price ($/Ton)"),'P&L Baseline'[Value]),
    "Costs($)",
    SUMX(FILTER(ALL('P&L Baseline'),'P&L Baseline'[Category] = "Costs($)"), 'P&L Baseline'[Value])
)

hi @CJ0323 

 

try like:

Total = 

SWITCH(

    SELECTEDVALUE('P&L Baseline'[Category]),

    "Contract Price ($/Ton)", AVERAGEX(FILTER(ALL('P&L Baseline'),'P&L Baseline'[Category] = "Contract Price ($/Ton)"),'P&L Baseline'[Value]),

    "Costs($)",

    SUMX(FILTER(ALL('P&L Baseline'),'P&L Baseline'[Category] = "Costs($)"), 'P&L Baseline'[Value])

)

This appears to work well! Could I scale this to N number of categories?

No luck!
Error  is "Too many arguments were passed to the selectedvalue() function. The maximum argument count for the function is 2."

CJ0323_0-1674511411833.png

 

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.