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
Kylie
New Member

Sum and average values in one measure

Hi,

 

I have a measure always filtered by one text column (Type Name):

Kylie_0-1652638060642.png

These values are historized on a quarterly basis (with the first date of the quarter). And now I need to implement the following logic: when evaluating multiple quarters at the same time (for example, having multiple choice in the date column filter), the measure numbers should be averaged. In the case of one quarter, the values should be summarized.

 

I can't think of any ideas, so any tips will help me!

Thanks in advance

Kylie

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Kylie,

You can write a measure with a switch function to check the filter selections, then you can navigate to the different expressions based on the selected value.

formula =
VAR selceted =
    SELECTEDVALUE ( NewTable[Type Name] )
RETURN
    SWITCH (
        selceted,
        "Sum", SUM ( Table[Sale] ),
        "Average", AVERAGE ( Table[Sale] )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @Kylie,

You can write a measure with a switch function to check the filter selections, then you can navigate to the different expressions based on the selected value.

formula =
VAR selceted =
    SELECTEDVALUE ( NewTable[Type Name] )
RETURN
    SWITCH (
        selceted,
        "Sum", SUM ( Table[Sale] ),
        "Average", AVERAGE ( Table[Sale] )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Whitewater100
Solution Sage
Solution Sage

Hi Kylie:

Please see attached file with the results I hope you are excpecting.

https://drive.google.com/file/d/1JFg76rkWlb4PgO361geAg5Jz_ImVTawk/view?usp=sharing 

I have set up a file with a basic model and calulations. If you select one quarter,the results are just for that Qtr, when selecting multiple Q's the results are averaged. I used some made up data to demonstrate.

 

Whitewater100_0-1652640638777.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.

Top Solution Authors