Forum Discussion

ARTarabein's avatar
ARTarabein
New Member
7 years ago
Solved

Count Values in TTM Measure

Hi, 

 

I am trying to come up with the count of values that are yielding my TTM Measure total. The aim is to make sure that there is always 12 month of values yielding my current and Last Year TTM otherwise I want to exclude from dashboard (it is a same store dashboard) 

 

I am using the following measure:

TTM:=CALCULATE([Mnth],DATESINPERIOD(dDate[Date],max(dDate[Date]),-12,MONTH))

Last Yr TTM:=CALCULATE([TTM],SAMEPERIODLASTYEAR(dDate[Date]))

YoY TTM %:=if([Last Yr TTM]>0,if([TTM]>0,DIVIDE([TTM]-[Last Yr TTM],[Last Yr TTM])))

 

Thank you in advance

  • ARTarabein's avatar
    ARTarabein
    7 years ago

    So I figured this one out:

     

    to count mnth in current quarter 

    Count:=CALCULATE(COUNT([Sales]),DATESINPERIOD('Calendar'[Date],MAX('Calendar'[Date]),-1,QUARTER))

     

    to count mnths in last year quarter:

    Last Count:=CALCULATE([Count],SAMEPERIODLASTYEAR('Calendar'[Date]))

     

    then my current quarter total sales would be

    SSQUARTER:=if(and([Count]=3,[Last Count]=3),CALCULATE(sum([Sales]),DATESINPERIOD('Calendar'[Date],max('Calendar'[Date]),-1,QUARTER)))

     

    And last year's 

     

    SSLastQ:=if(and([Count]=3,[Last Count]=3),CALCULATE([QUARTER],SAMEPERIODLASTYEAR('Calendar'[Date])))

3 Replies

  • Hi,

    Your question is not clear.  Share some data, explain the business question and show the expected result.

    • ARTarabein's avatar
      ARTarabein
      New Member

      appreciate the reply

       

      I ll rephrase my question using quarter calculations for compact data representation:

       

      lets assume I have the following data set showing current and last year's first quarter sales of two stores A & B

      DateStoreSales
      Jan-18A23
      Feb-18A45
      Mar-18A34
      Jan-19A12
      Feb-19A34
      Mar-19A62
      Feb-18B32
      Mar-18B55
      Jan-19B14
      Feb-19B23
      Mar-19B56

       

      my aim is to do a same store analysis showing last year quarter vs current year but I only want to show stores that have full 3 month of sales in each quarter. You can see that I have set Store B to be opened in Feb 18 so it does not have Jan-18 sales data thus I want Store B to be excluded from my pivot. 

       

      in order to do so, I have created the following measures to calculate Current Quarters sales, Last year Quarter Sales, and Year on Year % change: 

      Quarter:=CALCULATE(sum([Sales]),DATESINPERIOD('Calendar'[Date],max('Calendar'[Date]),-1,QUARTER))

      Last Yr Quarter:=CALCULATE([Quarter],SAMEPERIODLASTYEAR('Calendar'[Date]))

      YoY %:=if([Last Yr Quarter]>0,if([Quarter]>0,DIVIDE([Quarter]-[Last Yr Quarter],[Last Yr Quarter])))

       

      my outcomes shows :

      Row LabelsQuarterLast Yr QuarterYoY %
      A1081025.9%
      B93876.9%

       

      what I cannot figure out is how to identify that Store B does not have full 3 month of sales in last year quarter thus 

      excluding it from pivot?!! 

      My initial thought is to find a way to count the number of values excel uses to calculate my current and last year quarter sum and exclude it if less than 3. 

       

      hope this explain my problem and I really appreciate your attempt to help.

      • ARTarabein's avatar
        ARTarabein
        New Member

        So I figured this one out:

         

        to count mnth in current quarter 

        Count:=CALCULATE(COUNT([Sales]),DATESINPERIOD('Calendar'[Date],MAX('Calendar'[Date]),-1,QUARTER))

         

        to count mnths in last year quarter:

        Last Count:=CALCULATE([Count],SAMEPERIODLASTYEAR('Calendar'[Date]))

         

        then my current quarter total sales would be

        SSQUARTER:=if(and([Count]=3,[Last Count]=3),CALCULATE(sum([Sales]),DATESINPERIOD('Calendar'[Date],max('Calendar'[Date]),-1,QUARTER)))

         

        And last year's 

         

        SSLastQ:=if(and([Count]=3,[Last Count]=3),CALCULATE([QUARTER],SAMEPERIODLASTYEAR('Calendar'[Date])))