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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sbeldona
Frequent Visitor

Calculating difference in a variable based on two different dates selected from a slicer

I have a data set that contains values of enrollment for 100s of courses by date as shown below.  And typically these dates go for about 40 days before class begin.

What I am trying to figure out is how can I show the delta (difference) between enrollment by course when a user selects a range of dates.  Any help would be greatly appreciated.  And I am very new to DAX.  So if there is anyone who can help me here it would be appreciated.

CourseEnrollmentDate
ABC185/1/2019
XYZ95/1/2019
ABC195/2/2019
XYZ95/2/2019
ABC205/3/2019
XYZ125/3/2019
ABC245/4/2019
XYZ185/4/2019
CDF85/5/2019
ABC255/5/2019
1 ACCEPTED SOLUTION

Hi @sbeldona ,

Does that make sense? If so, kindly mark my answer as a solution to help others having the similar issue and close the case. If not, let me know and I'll try to help you further.

Best regards
Amy Cai

View solution in original post

5 REPLIES 5
v-xicai
Community Support
Community Support

Hi @sbeldona ,

 

Try to create measure using DAX below. Or could you please share your sample data or desired output screenshots for further analysis? You can also upload sample pbix to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Differ = CALCULATE(MAX(Table1[Enrollment]),FILTER(Table1,Table1[Course]=MAX(Table1[Course])&&Table1[Date]=LASTDATE(Table1[Date])))-CALCULATE(MAX(Table1[Enrollment]),FILTER(Table1,Table1[Course]=MAX(Table1[Course])&&Table1[Date]=FIRSTDATE(Table1[Date])))

 

Best Regards,

Amy

 

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

 

@v-xicai 

Hi Amy, thanks for your reply.  Here is the link to a masked sample data 

https://1drv.ms/x/s!AtSzBDgGn5HqfKpYnzs0uaOi5DQ

 

What I need is something like this in BI to display based on the Enroll Dates choosen by a user.  In this case Date1 and Date 2 are choosen by a user on a slicer that is made avialable.

 

SubjectDate1Date 2Differ
ACCT30355
BUAD40477
BANA43507
MANA50544
Total16318623

 

 

Also, is it possible to create a line chart where on the X axis we have a Subject and on the Y axis are the DATE1 and DATE2 numbers.  Again, these DATE1 and DATE2 dates are choosen by a user using the slicer.

 

Your help would be so much appreciated.

Hi @sbeldona ,

Does that make sense? If so, kindly mark my answer as a solution to help others having the similar issue and close the case. If not, let me know and I'll try to help you further.

Best regards
Amy Cai

Hi @sbeldona ,

 

I am not sure about how to get the Date1 and Date2, is it referred to lowest and highest date of the range date slicer ? If yes, you can create measures [Date1 ] and [Date2] using DAX below.

 

Date1= CALCULATE(MAX(Table1[Enrollment]),FILTER(Table1,Table1[Course]=MAX(Table1[Course])&&Table1[Date]=FIRSTDATE(Table1[Date])))

 

Date2 = CALCULATE(MAX(Table1[Enrollment]),FILTER(Table1,Table1[Course]=MAX(Table1[Course])&&Table1[Date]=LASTDATE(Table1[Date])))

 

Differ = [Date2]-[Date1]

 

1.png2.png

 

 

 

 

 

 

 

 

Best Regards,

Amy

 

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

 

Thanks so much.  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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