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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
ybicalways79
Frequent Visitor

DAX - Changing Between SUM and AVERAGE in a Matrix

Help!

 

I attempted multiple measures to get the results i need.  I can do either SUM or AVERAGE but not both.  Where am i going wrong?

 

ybicalways79_0-1687352572892.png

 

ybicalways79_1-1687352624173.png

 

FormatMetric OperationalSales =
VAR Val = SUM ( SalesData[Value] )      
RETURN      
    SWITCH (    
        SELECTEDVALUE ( SalesData[Attribute] ),
        "Overall Sales"FORMAT (Val, "$#,##0;($#,##0)" ),
        "Overall Conversion (%)"FORMAT (Val, "0.0%" ),
        "Overall Margin (%)"FORMAT (Val, "0.0%" ),
        "Overall Lookup (Ct.)"FORMAT (Val, "0" )
)
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @ybicalways79 
Please try

FormatMetric OperationalSales =
VAR Val =
    SUM ( SalesData[Value] )
VAR Ave =
    AVERAGE ( SalesData[Value] )
RETURN
    SWITCH (
        SELECTEDVALUE ( SalesData[Attribute] ),
        "Overall Sales", FORMAT ( Val, "$#,##0;($#,##0)" ),
        "Overall Conversion (%)", FORMAT ( Ave, "0.0%" ),
        "Overall Margin (%)", FORMAT ( Ave, "0.0%" ),
        "Overall Lookup (Ct.)", FORMAT ( Val, "0" )
    )

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @ybicalways79 
Please try

FormatMetric OperationalSales =
VAR Val =
    SUM ( SalesData[Value] )
VAR Ave =
    AVERAGE ( SalesData[Value] )
RETURN
    SWITCH (
        SELECTEDVALUE ( SalesData[Attribute] ),
        "Overall Sales", FORMAT ( Val, "$#,##0;($#,##0)" ),
        "Overall Conversion (%)", FORMAT ( Ave, "0.0%" ),
        "Overall Margin (%)", FORMAT ( Ave, "0.0%" ),
        "Overall Lookup (Ct.)", FORMAT ( Val, "0" )
    )

Thank you!  I was so close on this one!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.