Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Need previous period logic

Hi All,

i need logic for previous metric.
there are 2 filters period type and period name
when i select period type=month and period name=May or period name = (May ,april)
current should show may data and previous should show april data

 

similarly when i select period type=month and period name=april or period name=(april,march)
current=april data and previous=march data

 

similarly when i select period type=Qtr and period name=Q2 or period name=(Q2,Q1)
current=Q2 data and previous=Q1 data

 

need you help in getting previous metric when we select above filter scenarios(either selecting period name current or current & previous would work)
I was not able to find how to attach PBIX file so i am pasting the sample data and output required below - 

 

Period KeyPeriod TypePeriod NameDateGroupQuantity
1MonthMay12-MayA20
1MonthMay15-MayA5
1MonthApr7-AprA15
1MonthApr15-AprA10
1MonthMar23-MarA5
1MonthFeb15-FebA20
1MonthMay15-MayB20
1MonthApr10-AprB30
1MonthMar28-MarB30
1MonthFeb11-FebB10
2QtrQ212-MayA20
2QtrQ215-MayA5
2QtrQ27-AprA15
2QtrQ215-AprA10
2QtrQ123-MarA5
2QtrQ115-FebA20
2QtrQ215-MayB20
2QtrQ210-AprB30
2QtrQ128-MarB30
2QtrQ111-FebB10

 

below should be the output when i select below filters

 

when i select period type=month and period name=april or period name=(april,march)
current=april data and previous=march data

 

GroupCurrentPrevious
A255
B2030

 

Thanks,

Raj

7 Replies

  • Anonymous 

     

    I create a datetime table and create relationship between fact and datetime table.

    You can create quarter ,month name in the datetime table.

    Then you create a measure for previous month qty.

    Measure = CALCULATE(sum('table'[Quantity]),DATEADD('datetime'[Date],-1,MONTH))

     The month column you used for the filter should come from datetime table.

    • Anonymous's avatar
      Anonymous
      Not applicable

      how does it work when i select quarter? even i have week,year,quarter,month,LTD as values in period type and relevant values in  period name

      ex - when i select period type=Qtr and period name=Q2 or period name=(Q2,Q1)
      current=Q2 data and previous=Q1 data

       

      UI looks something like this. period type and period name are like relevant filters.

       

       

       

  • Hi,

    In your Data, what is the relevance of the Period Type and Period Names columns?  The Month and Quarter should get deterined from the Date column itself.  Also, if the user selects only 1 month, then you can get your desired result.

    Please let me know.

    • Anonymous's avatar
      Anonymous
      Not applicable

      this is the datastructure in my table and i cannot change the struucture as there is more complexity involved which would impact other tables..i am trying to get the solution with this structure.

      • ryan_mayu's avatar
        ryan_mayu
        Icon for Super User rankSuper User

        Anonymous,

         

        Create a measure to calculate last quarter value.

         

        Measure = CALCULATE(SUM(Sheet11[Quantity]),DATEADD('datetime'[Date],-1,QUARTER))

         

        Quarter filter should also come from the datetime table.