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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate number of sales last yaerweek when this yearweek has no sales

Hello!

 

I'm trying to calculate the amount of sold products from last year so I can compare them with the amount of sold products this year. When a product has no sells in a week, the number of sold products last year has not been calculated. 

 

The picture below shows difference between week 3, 5 and 6. 

 

Total sales TY and LY. Difference between total and yearweek.Total sales TY and LY. Difference between total and yearweek.             LY SalesLY Sales

 

Using same period last year will not work, because this formula takes only dates into account and my table only no dates, but only yearweek. I do have a calendar table with date, year, year_iso, weeknum, yearweek, month etc. 

 

At the moment I'm using the fomula:

 

LY_sold1 = VAR CurrentWeek = SELECTEDVALUE( Calendar[week])
VAR CurrentYear = SELECTEDVALUE( Calendar[year_iso])
RETURN
CALCULATE(IF(ISBLANK(SUM(Order[Number])); 0; SUM('Order'[Number])); FILTER( ALL( Calendar ); Calendar[week] = CurrentWeek && Calendar[year_iso] = CurrentYear - 1 ) )
 
and 
 
LY_sold = SUMX(
SUMMARIZE( Calendar; Calendar[YearWeek]; Calendar [week];
"Formula"; [LY_sold1]);
[Formula] )

 

Does anyone know how I can calculate the sales of last year even when there are this yearweek no sales?

2 REPLIES 2
dax
Community Support
Community Support

Hi K_p

Did you want to achieve result like below?

397.PNG

If so, you could refer to my sample. If not, please correct me and inform me more detailed information (such as your sample data and your expected output).

Please do mask sensitive data before uploading.

Thanks for your understanding and support.
Best Regards,
Zoe Zhi

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

Anonymous
Not applicable

Thank you for your reply!

 

 

What I would like to do is to display one table with the results of the sales from this year. I actually meant to say is that I would like to see the results of 2018 in the table of 2019 (see attached file). 

 

As example, when the slicer selects customer 'a' then I do not see this customer ordered also product y in week 4 of 2018. 

When I select everything, the totals in last year sold are correct, although not all data is displayed in the table. 

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.