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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
JDU
Helper I
Helper I

DAX to sum only the partial sales of the previous year

Dear, I need your help with a measure in DAX to sum only the partial sales of the previous year with the final objective to be able to compare in a label with the sales of the current year.

238.487.695.jpg

The cumulative for the first three months of the previous year (2022) is 238,487,695, then a measure is required that is capable of calculating it for comparison with YTD (2023). Obviously it must be dynamic to be able to always compare Sale Ytd /SamePeriod Last Ytd.

Thank you very much for your cooperation.

13 REPLIES 13
MohammadLoran25
Solution Sage
Solution Sage

Hi @JDU ,

You just need a "DateTable" to Handle it with the measure below:

 

CALCULATE (
    [YourSalesMeasure],
    FILTER (
        ALL ( 'DateTable' ),
        DateTable[Year]
            = YEAR ( TODAY () ) - 1
            && DateTable[Date] <= TODAY ()
    )
)

 

If this answer solves your problem, give it a thumbs up and mark it as an accepted solution so the others would find what they need easier.

Regards,
Loran

Thank you Mohammad for the reply. I tried with the formula but it does not give any result.

Captura de pantalla 2023-04-12 132004.png

Question: Year in the sixth line is a function?
(Note: I am working with a calendar table).

@JDU ,

Sorry I did sth wrong. This should be:

 

CALCULATE (
    [YourSalesMeasure],
    FILTER (
        ALL ( 'DateTable' ),
        DateTable[Year]
            = YEAR ( TODAY () ) - 1
            && DateTable[Date] <= DATE(YEAR(TODAY()-1),MONTH(TODAY()),DAY(TODAY())
    )
)

 

 

AND yes YEAR is Function in your line 6.

I have a problem with the DATEADD function, it does not recognize the function today.

Captura de pantalla 2023-04-12 134702.png

My bad. Edited.

Btw your previous measure should returns an output as well. What is your [Total Ventas] Measure?

I'm sure I'm doing something wrong, maybe there is a problem in the calendar table or in some measure, but I keep getting an error.

Captura de pantalla 2023-04-12 172341.png

Regarding the Total Ventas measure, it is simply the sum of sales per month.

Total Ventas = sum(Hoja1[Ventas] )
 
Thank you for your help.

@JDU Please send the error of the visual.

Good morning,
It is in Spanish but basically what it says is that DAX comparison operations do not support comparison values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

Captura de pantalla 2023-04-14 074217.png

@JDU Hi again

I think the year column in your date table is in Text format.

Change its format or use CONVERT function.

@JDU Hi again

I think the year column in your date table is in Text format.

Change its format or use CONVERT function.

You were right, the problem was the format, however, what the function does is to add up all the previous year and what I need is to add up only the same period of time of this year to compare the percentage variation of sales.

 

hoy.jpg

@JDU 

We need to edit this part of the code:

Instead of:

DATE(YEAR(TODAY()-1),MONTH(TODAY()),DAY(TODAY())

 

Put the below then u get what you want:

DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY())

 

Regards,

Loran

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.