Forum Discussion

jherbert1017's avatar
jherbert1017
New Member
6 years ago
Solved

comp date measure

New to Dax and trying to figure this out,  I have two tables as below.  Trying to calculate a measure that will sum the income based on the comp date when the slicer on the page is set to the visit date.  There is a relationship between the two tables with the visit date columns in each, but i also merged the two tabels in the power query to add the comp date column to the transaction table.  Wasn't sure which way was better on performance as I have roughly 70M rows of transactions(that will continue to grow) and am trying to optimize performance as well.

So ultimately the result i am looking for is when the visit date is 7/1/2020 would be income $15 (sum of 7/3/2019), visit date 7/2/2020 would be income $13 (sum of 7/4/2019) and visit date 7/3/2020 would be income $27 (sum of 7/5/2019)

 

Your help is greatly appreciated!

 

Transaction table

Visit DateIncomeComp Date
7/3/2019107/5/2018
7/3/201957/5/2018
7/4/2019137/6/2018
7/5/2019207/7/2018
7/5/201937/7/2018
7/5/201947/7/2018
7/1/202057/3/2019
7/1/2020107/3/2019
7/2/20203.57/4/2019
7/3/202077/5/2019
7/3/202087/5/2019

 

Calendar Table

Visit DateComp Date
7/1/20207/3/2019
7/2/20207/4/2019
7/3/20207/5/2019
  • Anonymous's avatar
    Anonymous
    6 years ago

    Hi jherbert1017 

    I build two table like yours to have a test.

    Transaction table:

    You dont need to merge Transaction table and Calendar Table. And if you feel your report is slow and performance is not good, you may need to optimize performance. For more info about optimize performance:Optimization guide for Power BI

    You may achieve your goal by measure.

    Firstly we use Visit Date in Calendar Table to build a Slicer.

    Then we build a measure as below:

     

     

    TotalIncome = 
    CALCULATE(SUM('Transaction'[Income]),FILTER(ALL('Transaction'),'Transaction'[Visit Date]=MAX('Calendar'[Visit Date])))

     

     

    Add this measure in a card visual or Transaction table visual to show the result.

    Result:

    Select 2019/7/4 in slicer

    You can download the pbix file from this link: Comp date measure

     

    Best Regards,

    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

4 Replies