Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Display data for previous 6 months

Hello,

I have a fact table and a dimension date table related with each other through the date columns (Date - Created_On). I have to filter the month in slicer and to display the number of applications for the last 6 month excluding the selected month. And the average of applications for the last 6 months excluding the selected month. 
I have tried this formula. 

Last 6 months=
var app =calculate(
    DISTINCTCOUNT(FactTable[Original_ID]),
    filter(AFactTable,FactTable[Original_ID]]<> blank()),
    DATESINPERIOD (
        DimDate[Date],
         EOMONTH ( TODAY (),-1),
        -6,
        MONTH
    )
)
return
if(isblank(app),0,appt)
 
But this formula gives me the last 6 months only when I dont select months in a slicer. If I filter the data through the slicer, it gives me the vales of the selected month only. I need to show the data for the last 6 months previous the selected month. 


Thanks in advance!

 

FactTable  
Original_Id   Created on 
11/2/2021
21/3/2021
31/4/2021
41/5/2021
Dimdate  
YearMonthDate
2021Jan1/2/2021
2022Feb1/2/2022
2021Mar1/3/2021
2021Apr1/4/2021
  • Anonymous , If you want to select a month and want to show more than that on the axis/row, the slicer needs to be on an independent date table

     

    //Date1 is independent Date table, Date is joined with Table
    new measure =
    var _max = maxx(allselected(Date1),Date1[Date])
    var _min = eomonth(_max, -6) +1
    return
    calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

     

    Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

  • Anonymous's avatar
    Anonymous
    4 years ago

    HI amitchandak 
    It helped me a lot a formula used in the video you shared.
    Nr of app in the last 6 months=

    CALCULATE ( DISTINCTCOUNT(FactTable[Original_ID]),
        DATESINPERIOD (
           DimDate[Date],
           EOMONTH( MAX ( DimDate[Date]),-1), -6,
            MONTH
        )
    )

7 Replies

  • Anonymous , If you want to select a month and want to show more than that on the axis/row, the slicer needs to be on an independent date table

     

    //Date1 is independent Date table, Date is joined with Table
    new measure =
    var _max = maxx(allselected(Date1),Date1[Date])
    var _min = eomonth(_max, -6) +1
    return
    calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

     

    Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

    • Anonymous's avatar
      Anonymous
      Not applicable

      HI amitchandak 
      The problem is that in the same report I have to display different data (measures) for the selected months, for previous month and the last 6 months excluding the selected one, in order to compare the data. So the slicer should be the one from DimDate table.

    • Anonymous's avatar
      Anonymous
      Not applicable

      HI amitchandak 
      It helped me a lot a formula used in the video you shared.
      Nr of app in the last 6 months=

      CALCULATE ( DISTINCTCOUNT(FactTable[Original_ID]),
          DATESINPERIOD (
             DimDate[Date],
             EOMONTH( MAX ( DimDate[Date]),-1), -6,
              MONTH
          )
      )
  • tamerj1's avatar
    tamerj1
    Icon for Community Champion rankCommunity Champion

    Hi Anonymous 
    Please refer to this sample file based on sales table. However, you can follow the same method but replace with the desired aggregation. 

    • Anonymous's avatar
      Anonymous
      Not applicable

      The Year Month in slicer is from the Date table?

      • tamerj1's avatar
        tamerj1
        Icon for Community Champion rankCommunity Champion

        Anonymous 
        Yes. But in the table visual itself you are slicing by the PreviousDate table.