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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
RonHall
Frequent Visitor

Before and After using One Date

I have a table called "Combined" with a column for "Date".  The table is a list of activities.  I have built a dates table using dax and set it up as a sicer. It is called "DatesTable" and the column with the dates is called "SelectedDate"  I want to be able to select a date from this drop down and then with two measures show the activites 90 days before this date (Before) and 90 days after this date (After).

 

If I hard code the dates into the mesaure it works just fine ...

Before = CALCULATE(COUNTROWS(Combined), DATESBETWEEN(Combined[Date], Date(2017,1,1), Date(2017,3,31)))

After2 = CALCULATE(COUNTROWS(Combined), DATESBETWEEN(Combined[Date], Date(2016,10,1), Date(2017,1,1)))

 

But when I try to use the dates from the drop down it doesn't.

 

Before = CALCULATE(COUNTROWS(Combined), DATESBETWEEN(Combined[Date], 'Dates Table'[SelectedDate], 'Dates Table'[SelectedDate]+90))

After = CALCULATE(COUNTROWS(Combined), DATESBETWEEN(Combined[Date], 'Dates Table'[SelectedDate], 'Dates Table'[SelectedDate]-90))

 

I tried making the dates from the dates table into measures and dropping them in but that didnt work either.  Any suggestions?

1 ACCEPTED SOLUTION

I figured it out, when I changed my date selector to the date within the combined table it works. I had it as my date table previously.

View solution in original post

4 REPLIES 4
MFelix
Super User
Super User

Hi @RonHall,

 

According to what I understand you want to calculate the Before and After based on a slicer you made with the SelectedDate, to make this you need to know what is the selected date so in the dates table make this measure:

 

DateSelected = Max('Dates Table'[SelectedTable])

 

Now use this measure in your Before and after should look something like this:

 

Before = CALCULATE(COUNTROWS(Combined), DATESBETWEEN(Combined[Date], [DateSelected], [DateSelected]+90))

After = CALCULATE(COUNTROWS(Combined), DATESBETWEEN(Combined[Date], [DateSelected], [DateSelected]-90))

 

Regards

 

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you for the input, the measures work and the dates change when I select a new date from the drop down, but the bar chart where I have Before and After doesn't.  It shows one set of data and does not change when I change the date in the drop down.

Actually it is changing, but the values for before and after are exactly the same every time.

 

I figured it out, when I changed my date selector to the date within the combined table it works. I had it as my date table previously.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors