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
ViktorT
Frequent Visitor

Cumulative Yearly sales vs Previous Year

Maybe this question is already asked using different wording that I am not aware of, please feel free to just link me to that if so.

 

I have managed to make the cumulative sales per year based on the input from the forum. However I experience difficulties in comparing YoY numbers. I constructed following measures 

 

 

Acc Sales (SEK) = 
CALCULATE(
Sum(Sales[GS value acc. (SEK)]);filter(All(Sales[YearMonth]);Sales[YearMonth] <= MAX(Sales[YearMonth]) && Year(Today())=Year(Sales[YearMonth]));Sales[YearMonth])

 

 

 

Acc LY Sales (SEK) = 
CALCULATE(
Sum(Sales[GS value acc. (SEK)]);filter(All(Sales[YearMonth]);Sales[YearMonth] <= MAX(Sales[YearMonth]) && Year(Today())-1=Year(Sales[YearMonth]));Sales[YearMonth])

image.png

 

 

To use these measures in the correct way, I cannot use the Date hierarcy of the field YearMonth, I have to use the continous date which means I cannot remove the year.

 

I changed the formula to this, using a month field instead of a date field. And this is where it starts behaving wierd in my eyes. 

 

 

Acc LY (SEK) = 
CALCULATE(
	Sum(Sales[GS value acc. (SEK)]);filter(All(Sales[YearMonth]);Sales[YearMonth] <= MAX(Sales[YearMonth]) && Year(Today())-1=Year(Sales[YearMonth]));Sales[Month])

Acc LY (SEK) = 
CALCULATE(
	Sum(Sales[GS value acc. (SEK)]);filter(All(Sales[YearMonth]);Sales[YearMonth] <= MAX(Sales[YearMonth]) && Year(Today())-1=Year(Sales[YearMonth]));Sales[Month])

 

If I use both year and month in cumulates in the correct way, if I remove the year only using month, current years numbers cumulates, LY shows only the total, but cumulates for where there are no data in current year.

 

image.pngimage.png

 

Is my question making any sense? What am I doing wrong here?

 

Regards

VIktor

 

 

1 ACCEPTED SOLUTION

Hi,

May I suggest you to take a look at the Time patterns at DAX Patterns?. There you will find many examples of calculations like the one you need to perform.

If that does not help, then we can work on your model (for this, I would need a sample PBIX file) but, as of now, your code seems a complex solution for a simple problem, because you are not taking advantage of the standard time intelligence functions.

 

Have fun with DAX!

 

Alberto Ferrari
http://www.sqlbi.com

 

 

 

Alberto Ferrari - SQLBI

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

Hi, I have a list of 5 State Financial years ranging from 2013 to 2018. I am able to calculate difference between two consecutive years(2017,2018) and difference between current year 2018 with any previous year but not able to calculate difference for previous years like (2015,2017)

The DAX functions I used here are: YTD= Total YTD([Value], (Date), “6/30”)
PYTD = Calculate([YTD], Datesbetween(Date), Date(2013,7,1), Date(2017,6,30)))

Can someone assist me here? Thanks!

Hi,

 

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi, I would have loved to share but cannot due to confidentiality.

Please let me know if my DAX formulas are incorrect.

Hi,

 

I cannot visualise your result actually.  Share a dummy dataset which i can paste into Excel and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Sure, I will
Anonymous
Not applicable

Hi Avinash,

 

I have attached two files with dummy data, first file is 2015 vs 2018 where the Difference between these two years is coming fine.

Second file is comparison between 2015 vs 2017 where Difference is not being populated at all. Please let me know if this helps. 2015 vs 2017.PNG2015 vs 2018.PNG

 

 

Hi,

 

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

May I suggest you to take a look at the Time patterns at DAX Patterns?. There you will find many examples of calculations like the one you need to perform.

If that does not help, then we can work on your model (for this, I would need a sample PBIX file) but, as of now, your code seems a complex solution for a simple problem, because you are not taking advantage of the standard time intelligence functions.

 

Have fun with DAX!

 

Alberto Ferrari
http://www.sqlbi.com

 

 

 

Alberto Ferrari - SQLBI

Thanks Alberto

 

It just seems to be so strange that you need to have an "external" date table, and then everything is so simple 😃

 

Regards
Viktor

Indeed, it is strange. The thing is that with an external table you gain a lot of flexibility in terms of what you can compute, if they did implement it with simpler functions, then it would have been much simpler to write standard calculations, but it would have been very hard to write the advanced ones.

As strange as it is, I think it is a good balance between power and simplicity. Or, if you prefer, I would not know how to make it better, so I take it as a very good choice 🙂


Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

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.