Forum Discussion

MCG's avatar
MCG
Icon for Helper I rankHelper I
4 years ago
Solved

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
 

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi MCG ,

     

    Your measure seems to be wrong:

     

    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)

     

    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.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MCG ,

     

    Your measure seems to be wrong:

     

    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)

     

    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.