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
Syndicate_Admin
Administrator
Administrator

Calculate Sales with respect to the previous Month.

Hello!

I am working with a sales base that contains all the sales of an eccommerce, this one is already worked previously and then uploaded to Power Bi.

What I want to do is two data cards, where it shows me the cumulative sales of the month and the cumulative sales of the day. To complement I want these to be colored green, if the cumulative sale of the month is greater than last month and if the sale of today is greater than the sale of the same day but last month, otherwise it is in red.

I am using the following measures

Ventas Totales = SUM(Tabla[Ventas])

Ventas Mes Anterior = 
CALCULATE([Ventas Totales], 
PREVIOUSMONTH(Ventas[Fecha]), 
REMOVEFILTERS(Ventas))

KPI MES = SWITCH(
                TRUE(),
                [Ventas Totales] < [Ventas Mes Anterior] , "#ff0000",
                [Ventas Totales] > [Ventas Mes Anterior] , "#009900",
                "FFFF00"
                )

Ventas Dia y Mes Anterior = CALCULATE([Ventas Totales],
                        DATEADD(Ventas[Fecha],-1,MONTH)
                        )

KPI DIAS= SWITCH(
                TRUE(),
                [Ventas Totales] < [Ventas Dia y Mes Anterior] , "#ff0000",
                [Ventas Totales] > [Ventas Dia y Mes Anterior] , "#009900",
                "FFFF00"
                )

Ayuda 1.PNG
When formatting a card object, it works as I want it to, but the problem is when I add a filter object that contains the categories of the products sold (Shirts, Pants, Jackets, etc.). When selecting a category to filter all the objects, they do not behave as they should (In the image the months with yellow color should be green and not Red).

If someone could help me with the right measurement so that when filtering I do the calculation well, I would appreciate them.
Ayuda 2.png

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Syndicate_Admin 

Your screenshot is not very clear. Could you share a sample with me and show me a clear screenshot with the result you want? This will make it easier for me to understand your requirement.

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Syndicate_Admin , You should use a date table, Is there any reason to use all on table

example 

Ventas Mes Anterior = 
CALCULATE([Ventas Totales], 
PREVIOUSMONTH(Fecha[Fecha]))

 

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

 

Why Time Intelligence Fails - Power bi 5 Savior Steps for TI: https://youtu.be/OBf0rjpp5Hw

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.