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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
JanainaFerreira
New Member

Calculate Sum with diferent filters

Hi guys,

 

I have an issue with a calculation in Power BI. Probably this is easier than I can think, but I'm struggling with that.

I need to calculate the Sum(Total Sales) by days filtered in a Slicer. I also need to filter by city and country where the sale was sold.

I created this Measure, but I want to calculate for different cities to show in a Matrix:

 

teste1 = CALCULATE(SUM('Sales'[Total Sales]/[AT US],'Sales'[Country]="US",'Sales'[City]="Miami")
 
CountryCityAT
USMiami[AT US]
ESMadrid[AT EU]
ESBarcelona[AT EU]
 
I want to calculate all the possibilities just in one measure. Is there some way to calculate as a IF formula?
 
*the measure [AT US] depends on the selected date in a Slicer, which is variable and its works correctly.
[AT US] = The stores in US opens every day, so 30/31 days
[AT EU] = The stores in EU doesn't open on weekend, so 21/22 days
 
Thanks for any help!!
 
5 REPLIES 5
JanainaFerreira
New Member

Thank you for your sugestion Sahir_Maharaj,

 

But didn't work yet. I did what you suggested, but column [AT] shows the value 1 or 0 for each row.

When I did the formula test1, the Sum(Total Sales) was divided by 1 or 0, and not the sum of days which I set on the Slicer.

Sahir_Maharaj
Super User
Super User

This will calculate the sum of total sales for the city "Miami" and also consider the value of [AT] for the country. You can repeat the same steps for other cities as well.

 

Hope this helps! 🙂


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Sahir_Maharaj
Super User
Super User

2. Use the calculated column in your measure:

 

teste1 = 
CALCULATE(
    SUM('Sales'[Total Sales]),
    'Sales'[City] = "Miami",
    'Sales'[AT]
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Sahir_Maharaj
Super User
Super User

Here's how you can do it:

 

1. Create a calculated column with the following formula:

 

AT =
IF('Sales'[Country] = "US", [AT US],
IF('Sales'[Country] = "ES", [AT EU],
[AT]))

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Sahir_Maharaj
Super User
Super User

You can create a calculated column to store the [AT] value based on the country and then use the calculated column in the measure.

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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