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
NJ81858
Helper IV
Helper IV

Measure Not Correct

Hello,

 

I am trying to create a 3-month rolling average of the percentage of sales that are at a physical location instead of online. This is achieved by summing the dollars for the last 3 months when the location is not blank, and dividing that by the total sum of the dollars for the last 3 months. The issue that I am having is that it is summing the total sales correctly, but when I add the condition that the location is not blank, it only sums for the most recent month.

 

Here is my measure for the numerator of my calculation:

_num = 

VAR _end = LASTDATE('Table'[Date])
VAR _start = FIRSTDATE(DATESINPERIOD('Table'[Date], _end, -3, MONTH))

RETURN CALCULATE(SUM([Sales]), DATESBETWEEN('Table'[Date], _start, _end), FILTER('Table', [Location] <> BLANK()))

 

Here is my measure for the denominator of my calculation:

_denom = 

VAR _end = LASTDATE('Table'[Date])
VAR _start = FIRSTDATE(DATESINPERIOD('Table'[Date], _end, -3, MONTH))

RETURN CALCULATE(SUM([Sales]), DATESBETWEEN('Table'[Date], _start, _end))

 

 

Here are the tables of the sales for the last 3 months, the left table has the filter that the Location is not blank, and the right table is everything.

Sales.PNG

Note that the totals at the bottom are what should be returned by my two measures.

 

When I calculate these measures for the end of March, these are the values that I get:

Sales Graph.PNG

 

From these results, the denominator is calculating correctly, but the numerator is ignoring the dates and only calculating for the most recent month, even though the only thing that is different is the addition of the condition that the location is not blank. Any help would be greatly appreciated!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @NJ81858 ,

 

Please try this measure:

_num = 

VAR _end = LASTDATE('Table'[Date])
VAR _start = FIRSTDATE(DATESINPERIOD('Table'[Date], _end, -3, MONTH))

RETURN CALCULATE(SUM([Sales]), DATESBETWEEN('Table'[Date], _start, _end), FILTER(ALL('Table'), [Location] <> BLANK()))

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @NJ81858 ,

 

Please try this measure:

_num = 

VAR _end = LASTDATE('Table'[Date])
VAR _start = FIRSTDATE(DATESINPERIOD('Table'[Date], _end, -3, MONTH))

RETURN CALCULATE(SUM([Sales]), DATESBETWEEN('Table'[Date], _start, _end), FILTER(ALL('Table'), [Location] <> BLANK()))

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

@Anonymous This worked thank you!

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.