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
ConnieMaldonado
Responsive Resident
Responsive Resident

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

6 REPLIES 6
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
Super User

@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.

 

 

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.

Greg_Deckler
Super User
Super User

@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!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

"DAX is easy, CALCULATE makes DAX hard..."
Appreciate you mentioning this.  I was doing this intuitively (because it was easier) and was concerned the shoe was goinig to drop one day.  TY ~ 👍

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.