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
Anonymous
Not applicable

Want to get Selected Date range (Start and End) from Date Slider Slicer in Direct Query Mode

Hi All,

I want to calculate 12 months rolling members retained. I have Date Slider Slicer in Power BI Report. 

 

Retention_In_12Months =
VAR CurrentDate = SELECTEDVALUE(RETENTION[fulldate])

VAR PreviousDate = CurrentDate - 365

RETURN
CALCULATE (
SUM ( RETENTION[Member_Retention] ),
FILTER (
RETENTION,
RETENTION[fulldate] >= PreviousDate
&& RETENTION[fulldate] <= CurrentDate
)
)
 
But It is not working.
 
How can I get Start and End date from Date Slider Slicer and use it in above calculation?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

This is how I achieved this:

SelectedDateStart = CALCULATE (
MIN (RETENTION[fulldate]),
FILTER (
ALLSELECTED (RETENTION[fulldate]),
RETENTION[fulldate] >= MIN (RETENTION[fulldate])
))
 
SelectedDateEnd = CALCULATE (
MAX (RETENTION[fulldate]),
FILTER (
ALLSELECTED (RETENTION[fulldate]),
RETENTION[fulldate] <= MAX (RETENTION[fulldate])
) )
 
 
Retention_In_12Months =
VAR CurrentDate = CALCULATE (
MAX (RETENTION[fulldate]),
FILTER (
ALLSELECTED (RETENTION[fulldate]),
RETENTION[fulldate] <= MAX (RETENTION[fulldate])
) )
VAR PreviousDate = CurrentDate - 365
 
RETURN
CALCULATE (
SUM ( RETENTION[LLC_Retention] ),
DATESBETWEEN (
RETENTION[fulldate], PreviousDate, CurrentDate
))

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

This is how I achieved this:

SelectedDateStart = CALCULATE (
MIN (RETENTION[fulldate]),
FILTER (
ALLSELECTED (RETENTION[fulldate]),
RETENTION[fulldate] >= MIN (RETENTION[fulldate])
))
 
SelectedDateEnd = CALCULATE (
MAX (RETENTION[fulldate]),
FILTER (
ALLSELECTED (RETENTION[fulldate]),
RETENTION[fulldate] <= MAX (RETENTION[fulldate])
) )
 
 
Retention_In_12Months =
VAR CurrentDate = CALCULATE (
MAX (RETENTION[fulldate]),
FILTER (
ALLSELECTED (RETENTION[fulldate]),
RETENTION[fulldate] <= MAX (RETENTION[fulldate])
) )
VAR PreviousDate = CurrentDate - 365
 
RETURN
CALCULATE (
SUM ( RETENTION[LLC_Retention] ),
DATESBETWEEN (
RETENTION[fulldate], PreviousDate, CurrentDate
))
amitchandak
Super User
Super User

@Anonymous , Create a date table ( you can have that in import mode if that not in DB)

Date as import mode -https://www.youtube.com/watch?v=cQfJ0GmQ5os&list=PLPaNVDMhUXGbKatyDdOhGbTL3xW2Xy6pA&index=7

Date in Database - https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-1-Time-Intelligence-in/ba-p/922885

 

Rolling 12 months measure

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

or

Rolling 365 day = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],MAX(Sales[Sales Date]),-365,Day))

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.