Forum Discussion

bilalkhokar73's avatar
bilalkhokar73
Icon for Helper IV rankHelper IV
5 years ago

Date selection before 3 ,after 3 month

When I select a date range then i want to get the sales that What was befpre 3 month sales and after 3 month sales

Let say i selected 01June to 30 June 2021 then i need to shwo in my stacked area graph that on this selected date range from date table 

So sin chart i will put month , i need sales when i select this date it shoudl give me march,april,may i.e (before 3 month) and june,july,august after 3 month like thiss

So on selected date range i need sales of that range beofre 3 month  and thsi 3 month, 

7 Replies

  • bilalkhokar73 , if you wanted data rolled at jun then

    Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD("Date"[Date ],eomonth(MAX("Date"[Date ]),-3)+1,6,MONTH))

     

     

    If you want a trend then you need to use an independent date table

    Need of an Independent Table in Power BI: https://youtu.be/lOEW-YUrAbE

    • bilalkhokar73's avatar
      bilalkhokar73
      Icon for Helper IV rankHelper IV

      I have date table, In my sales table I donto have data of april and may , then also it is givign me data fo april,may and dat comign wrong
      I need when i select June then last 3 monht and next 3 month sales june will be included in next 3 month
      Let say I seleted date from 15th june to 30 th june then data will come from 15th march to 15 april,15april to 15 may like this ....

      amitchandak 

      Desired result format

       

       

      • bilalkhokar73's avatar
        bilalkhokar73
        Icon for Helper IV rankHelper IV

        amitchandak 
        I have tried this but when i select july then it givess me only july sales
        I need when july select then july last 3 month and next 3 month like that 

        #Datesvprjt =

        var a=IF(ISFILTERED(Sales[Odate]),CALCULATE(sum(Sales[Amt]),FILTER(date,date[Date]>=MAX(Sales[Ordt])-90 && date[Date]<=MAX(Sales[Ordt])+90)),0)
        var b=CALCULATE(sum(Sales[Amt]),ALL(Sales[Amt]))
        return IF(ISFILTERED(Sales[Ordt]),a,b)

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, bilalkhokar73 ;

    You could create a date table as a slicer, and then create a measure.

    Rolling =
    VAR _per =
        EOMONTH ( MIN ( 'slicer'[Date] ), -3 )
    VAR _last =
        EOMONTH ( MAX ( 'slicer'[Date] ), 3 )
    RETURN
        CALCULATE (
            SUM ( [value] ),
            FILTER (
                ALL ( 'Table' ),
                [Date] <= MAX ( [Date] )
                    && [Date] >= DATE ( YEAR ( _per ), MONTH ( _per ), DAY ( MIN ( 'slicer'[Date] ) ) )
                    && [Date]<= DATE ( YEAR ( _last ), MONTH ( _last ), DAY ( MAX ( 'slicer'[Date] ) ) ))

    The final output is shown below:

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, bilalkhokar73 ;

    Is the above answer helpful to you? If so, Would you mind accept the helpful replies as solutions? Then we are able to close the thread. More people who have the same requirement will find the solution quickly and benefit here. Thank you.

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.