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
MCG
Helper I
Helper I

Measure to filter month sales data

Dear PBI Masters,

I got set of data showing sales for number of products ( a,b,c,d ets ) with historical month sales ( 18 months starting form 01/20 to 06/21)

I wanted to show sales only for those products that have zero sales in period 07-12/20. That was easy part:)

it goes like this:

Sales 6M before =
var max_date=CALCULATE(max('Months'[month]),ALL('Months'[month]))
var date_start=DATE(YEAR(max_data),MONTH(max_data)-6,1)
var date_end=DATE(YEAR(max_data),MONTH(max_data)-1,1)
var sales=CALCULATE([Sales],DATESBETWEEN('Months'[month],date_start,date_end))
return sales
 
Problem:
Figures are displayed in a table or grapf properly on condition that i put product on canvas.
Otherwise sales measure calculates sales of all products disregarding my condition
How should i deal with measures/ filters to get total sales od products with 0 zero sales in given period without showing product names in table/ chart?
 
thanks
mcg
 

 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @MCG ,

 

Your measure seems to be wrong:

Eyelyn9_0-1636338990024.png

 

Please try this instead:

Measure = 
var _maxDate=CALCULATE(max('Months'[Date]),ALL('Months'))
var _dateStart=DATE(YEAR(_maxDate)-1,MONTH(_maxDate)+1,1)
var _dateEnd=DATE(YEAR(_maxDate)-1,12,31)
var sales=CALCULATE(SUM(Months[Sales]),DATESBETWEEN('Months'[Date],_dateStart,_dateEnd))
return sales

 

If you want to dynamically show the X-axis base on the selected date period, you may apply a flag measure to filter pane ,like this:

Flag = 
var _maxDate=CALCULATE(max('Months'[Date]),ALL('Months'))
var _dateStart=DATE(YEAR(_maxDate)-1,MONTH(_maxDate)+1,1)
var _dateEnd=DATE(YEAR(_maxDate)-1,12,31)
return IF(MAX('Months'[Date]) >=_dateStart && MAX('Months'[Date])<=_dateEnd,1,0)

Eyelyn9_1-1636339397381.png

 

Best Regards,
Eyelyn Qin
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

1 REPLY 1
v-eqin-msft
Community Support
Community Support

Hi @MCG ,

 

Your measure seems to be wrong:

Eyelyn9_0-1636338990024.png

 

Please try this instead:

Measure = 
var _maxDate=CALCULATE(max('Months'[Date]),ALL('Months'))
var _dateStart=DATE(YEAR(_maxDate)-1,MONTH(_maxDate)+1,1)
var _dateEnd=DATE(YEAR(_maxDate)-1,12,31)
var sales=CALCULATE(SUM(Months[Sales]),DATESBETWEEN('Months'[Date],_dateStart,_dateEnd))
return sales

 

If you want to dynamically show the X-axis base on the selected date period, you may apply a flag measure to filter pane ,like this:

Flag = 
var _maxDate=CALCULATE(max('Months'[Date]),ALL('Months'))
var _dateStart=DATE(YEAR(_maxDate)-1,MONTH(_maxDate)+1,1)
var _dateEnd=DATE(YEAR(_maxDate)-1,12,31)
return IF(MAX('Months'[Date]) >=_dateStart && MAX('Months'[Date])<=_dateEnd,1,0)

Eyelyn9_1-1636339397381.png

 

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

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.