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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
kostask
Helper II
Helper II

Summarize data under conditions

Hi Guys.

I have a sales table with product categories and a calendar table.

I use the below measures to calculate the Sales YTD and LYTD

Sales YTD = CALCULATE[Sales] , YEAR('Sales Table'[Date]))
Instead of : Sales LYTD = CALCULATE( [Sales] , SAMEPERIODLASTYEAR('Calendar'[Date])) , i use:
Sales LYTD = IFISBLANK ( [Sales YTD]), ,
                             CALCULATE( [Sales] , SAMEPERIODLASTYEAR('Calendar'[Date])))
I use the previous formula, in order to appear the Sales LYTD as 0, if the Sales YTD are 0.
It works ok with the values, but not with the Total, where the result keeps summarizing the values i want to exclude.
Any idea?
Thank you 
Kostas
Capture.PNG
1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @kostask,

Mechanically, you achieve your objective by sumxing over the category field which you are bringing in your visualization rows, for row total to correctly add up with what's being shown in the visualization.  If you have a saparate category dimension table with one to many relationship with your fact table 'Sales Table' and the category field from the dimension field is properly used in your visualization, the formula will be referencing that dimension table Category field instead.    

Sakiko_0-1694559120205.png

A couple of observations:

Since you have properly created the calendar table for date dimension, what about writing the TotalYTD formula like below?

Sakiko_1-1694559597407.png

Also, the output produced in the above manner for omitting the previous year sales where there are no sales this year will generate rather misleading information (by omission), and the prior year sales total will not be consistent with the previously reported number.  

View solution in original post

3 REPLIES 3
sjoerdvn
Super User
Super User

If you want to exclude categories that have no sales this year in the mausure for the preceding year, that is not very hard to do, but you would need to give more info on your model, specifically if the categories are in a separate dimension, and if so, the columns involved in the relationship between that dimension and the sales fact table.

DataNinja777
Super User
Super User

Hi @kostask,

Mechanically, you achieve your objective by sumxing over the category field which you are bringing in your visualization rows, for row total to correctly add up with what's being shown in the visualization.  If you have a saparate category dimension table with one to many relationship with your fact table 'Sales Table' and the category field from the dimension field is properly used in your visualization, the formula will be referencing that dimension table Category field instead.    

Sakiko_0-1694559120205.png

A couple of observations:

Since you have properly created the calendar table for date dimension, what about writing the TotalYTD formula like below?

Sakiko_1-1694559597407.png

Also, the output produced in the above manner for omitting the previous year sales where there are no sales this year will generate rather misleading information (by omission), and the prior year sales total will not be consistent with the previously reported number.  

Thank you @DataNinja777 for the solution and the valuable recomendation!

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors