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
Anonymous
Not applicable

Calculate() filter doesn't return expected value

Hi,

 

I've been having issues with a measure that doesn't return the value you'd expect. I did find a topic where the user had the same issue, but the answer didn't quite explain why they should use ALL(), and in my case I do need filters to apply when calculating the measure : 

 

Monthly periodQuantityType
2021081Online
2021082Wholesale
2021095Wholesale
2021091Wholesale

 

 

Latest Quantity:=
VAR Max_Date =
    MAX ( 'Sales'[MONTHLY_PERIOD] )
RETURN
 CALCULATE (
                        SUM ( 'Sales'[Quantity] ),
                        Sales[MONTHLY_PERIOD] = Max_Date
                    )

 

 

This returns the entire sum of 9 whereas what I want it to return is 6, the sum for the latest period only.

I also want it to take into account the filters that are apply, so it should return 1 if I apply a 'Type = Online' filter.

 

Is there any way to resolve this ?

 

Thanks in advance.

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

I put your measure in a card visual and use a slicer to filter Type column. The result is correct as expected. See the attached pbix. Which visual do you put this measure in? If you put other columns into the same visual, they may provide some filters to the measure result. 

21112604.jpg

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

amitchandak
Super User
Super User

@Anonymous , Try like

 

Latest Quantity:=
VAR Max_Date =
MAXX (allselected('Sales'), 'Sales'[MONTHLY_PERIOD] )
RETURN
CALCULATE (
SUM ( 'Sales'[Quantity] ),
filter(sales, Sales[MONTHLY_PERIOD] = Max_Date)
)

Anonymous
Not applicable

Hi @amitchandak ,

 

Thanks for your answer, althouh I tried this solution and it still returns the total sum of the sales.

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.