cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ConnieMaldonado
Resolver II
Resolver II

Calculate Number of Days Between Slicer Dates

Hello:

I need to calculate average revenue by week by technician for dates entered via the standard date slicer.  So if the user selects 9/3/20 and 12/15/20 in the date slicer, I want to display the average revenue per week by technician.  I also have a slicer based on org (VP and Region) and need the rollups to calculate correctly.

 

Date Slicer.PNG

Date in Slicer.png

 

I need to sum the revenue between the slicer dates, as well as calculate the number of weeks and distinct techs between the slicer dates.  Once I have that, I can create a measure, do the division and calculate the average. 

 

My table has VP, Region, Tech Name, Tech Login, Invoice Date, Revenue Amt.  I also have a date dimension.

 

VPRegionTech NameTech LoginInvoice DateRevenue Amt
NorthConnecticutJohn SmithA123459/1/2020 $        1,200
NorthConnecticutJohn SmithA123459/2/2020 $           800
NorthConnecticutJohn SmithA123459/3/2020 $           775
NorthConnecticutJose PerezA234569/3/2020 $        2,035
NorthConnecticutJose PerezA234569/4/2020 $        1,280
NorthNew YorkJane SmithB1234510/3/2020 $           327
NorthNew YorkJane SmithB1234510/8/2020 $        2,055
NorthNew YorkJuan ValdezB2345610/15/2020 $        1,645
NorthNew YorkJuan ValdezB2345610/20/2020 $        1,835
NorthNew YorkCindy JonesC1234511/1/2020 $        1,190
SouthFloridaTed HallD1234511/2/2020 $           845
SouthFloridaTed HallD1234511/3/2020 $        1,320
SouthFloridaTed HallD1234511/3/2020 $        1,695
SouthFloridaTed HallD1234511/4/2020 $        1,550
SouthFloridaMaria PitaE1234511/10/2020 $        1,305
SouthFloridaMaria PitaE1234511/15/2020 $        1,290
SouthFloridaMaria PitaE1234511/16/2020 $        1,255
SouthFloridaJohn GuthrieF1234511/20/2020 $           302
SouthFloridaJohn GuthrieF1234511/22/2020 $        2,030
SouthGeorgiaLarry AlvarezG1234511/28/2020 $        1,620
SouthGeorgiaLarry AlvarezG1234511/29/2020 $        1,810
SouthGeorgiaLarry AlvarezG1234512/1/2020 $        1,165
SouthGeorgiaGeorge LucasH1234512/3/2020 $           820
SouthGeorgiaGeorge LucasH1234512/3/2020 $        1,295
SouthTexasBrian DeanJ1234512/4/2020 $        1,670
SouthTexasBrian DeanJ1234512/5/2020 $        1,525
SouthTexasBrian DeanJ1234512/7/2020 $        1,280
WestCaliforniaCharlie JonesK1234512/7/2020 $        1,265
WestCaliforniaCharlie JonesK1234512/8/2020 $        1,215
WestCaliforniaSara LuzL1234512/10/2020 $        1,265
WestUtahTed LandsM1234512/15/2020 $        1,315
WestUtahTed LandsM1234512/16/2020 $        1,365
WestUtahHarry PitcherN1234512/18/2020 $        1,415

 

Summing the revenue is easy as it will sum based on the slicer dates.  I created a measure to calculate number of distinct techs based on login. My issue is with calculating the number of weeks between the dates selected in the slicer.  How do I reference the slicer dates entered by the user so I can calculate the number of weeks between the 2 dates? 

 

Any help would be appreciated.  Thanks!

1 ACCEPTED SOLUTION

Thanks so much for your solutions!  I was able to calculate the number of weeks from the slicer dates using the following measures:

/* First date in slicer:

Selected Value MIN = CALCULATE(MIN('DATE Dim'[DATE]),ALLSELECTED('DATE Dim'))

/* Second date in slicer:

Selected Value MAX = CALCULATE(MAX('DATE Dim'[DATE]),ALLSELECTED('DATE Dim'))

/* Number of weeks between the 2 dates:

DAYS Between Slicer Dates = DATEDIFF(Revenue[Selected Value Min],Revenue[Selected Value MAX],WEEK)

 

I could have put this all in one formula but broke it up for illustrative purposes.

Couldn't have done it without you all!  Thanks.

View solution in original post

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Well, can someone help me count the number of days from a date slicer?

Hi,

Assuming the date slicer has been built from the Calendar Table, write this measure

Diff = max(calendar[date])-min(calendar[date])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User IV
Super User IV

@ConnieMaldonado , You can create a date table and week there and then you can divide by distinct weeks

new columns

 

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Number = WEEKNUM([Date],2)
Week = if('Date'[Week Number]<10,'Date'[Year]*10 & 'Date'[Week Number],'Date'[Year]&'Date'[Week Number])

 

 

or divide by


datediff(minx(allselected('Date'), 'Date'[Date]),maxx(allselected('Date'), 'Date'[Date]), WEEK)

datediff(minx(allselected('Date'), 'Date'[Date]),maxx(allselected('Date'), 'Date'[Date]), Day)/7

 

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 :radacad sqlbi My Video Series Appreciate your Kudos.

 

 



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Thanks so much for your solutions!  I was able to calculate the number of weeks from the slicer dates using the following measures:

/* First date in slicer:

Selected Value MIN = CALCULATE(MIN('DATE Dim'[DATE]),ALLSELECTED('DATE Dim'))

/* Second date in slicer:

Selected Value MAX = CALCULATE(MAX('DATE Dim'[DATE]),ALLSELECTED('DATE Dim'))

/* Number of weeks between the 2 dates:

DAYS Between Slicer Dates = DATEDIFF(Revenue[Selected Value Min],Revenue[Selected Value MAX],WEEK)

 

I could have put this all in one formula but broke it up for illustrative purposes.

Couldn't have done it without you all!  Thanks.

View solution in original post

Greg_Deckler
Super User IV
Super User IV

@ConnieMaldonado - Well, you can get the dates from the slicer using MIN and MAX. You could then use CALENDAR to create a date table as a VAR between those dates. Use ADDCOLUMNS to add a column using WEEKNUM. Then use DISTINCT and COUNTROWS to get the distinct weeks. Something along those lines.


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




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

Proud to be a Super User!




Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors