Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jherbert1017
New Member

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
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jherbert1017 

I build two table like yours to have a test.

1.png

Transaction table:

2.png

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.

2.png

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

3.png

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. 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @jherbert1017 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your problem or share me with your pbix file from your onedrive business.

 

Best Regards,

Rico Zhou

amitchandak
Super User
Super User

@jherbert1017 , Have a date table, join it with visit date active, and comp date inactive.

refer this blog How to work with inactive join using userelation

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

https://radacad.com/userelationship-or-role-playing-dimension-dealing-with-inactive-relationships-in...

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@jherbert1017 

 

you have to create a Calendar_dimensional table. 

Calendar_DatePeriodMonth_NameQuarterQuarter_NameWeek_of_PeriodWeek_of_YearWeek_NameYearDay_of_PeriodDay_of_YearDay_of_WeekCurrent_day_of_year
12/30/20191January1Q111Week 12020111154
12/31/20191January1Q111Week 12020222154

 

then you connect the calendar date to your transaction date 

 

create a measure similar to this 

=calculate(sum(sales),filter(dim_calendar,dim_calendar[day_of_year] = dim_calendar[current_day_of_year] && dim_calendar[year] = dim_calendar[year] - 1))

 

if this doenst make sense can you send some sample data and then i can share back with you

 

 

 

Anonymous
Not applicable

Hi @jherbert1017 

I build two table like yours to have a test.

1.png

Transaction table:

2.png

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.

2.png

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

3.png

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. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors