Forum Discussion

PieInDaFace's avatar
PieInDaFace
Frequent Visitor
8 years ago
Solved

Filtering with DatesInPeriod and Max

Howdy all,   I’ve been trying to get customers previous 3 sales for a while, and below is what I came up with, but man is it slow. Researching more, it seems due to using a max in the filter that c...
  • PieInDaFace's avatar
    PieInDaFace
    8 years ago

    v-ljerr-msft,

     

    Thanks for the reply. Turns out I was being a dunce and completely forgot about how to use the TopN function....

     

    Below is what I came up with for a faster measurement. 

     

    Max Trip Number:= MAX([TripNumber])

     

    Previous three Sales:=CALCULATE([Sales], Customers[Territory_Group] = "OOT", TOPN(3,DATESINPERIOD(‘Dates'[TimeDate],LASTDATE('Dates'[TimeDate]),-13,MONTH),[Max Trip Number],DESC ))

     

    For the table structure,

     

    Three tables

    • Customer table – distinct customers
    • Sales table – distinct sales, by customer, by date
    • Dates table – distinct date

    The relationship

    • Sales has a many to one between the customers table and dates table.
      • Many sales to one customer
      • Many sales to one date