Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
"๐๐ถ๐๐ฒ ๐บ๐ฒ ๐ฎ๐ป ๐ฒ๐ฎ๐๐ ๐ผ๐ฝ๐๐ถ๐ผ๐ป ๐๐ผ ๐๐๐ถ๐๐ฐ๐ต ๐ฑ๐ฎ๐๐ฒ ๐ฝ๐ฒ๐ฟ๐ถ๐ผ๐ฑ๐ & ๐พ๐ช๐จ๐ฉ๐ค๐ข ๐๐๐ฉ๐๐จ"
๐
Let's make it userfriendly and with a click of a button - the end user can set predefined date slicers + ๐ด๐ต๐ช๐ญ๐ญ ๐จ๐ช๐ท๐ฆ ๐ต๐ฉ๐ฆ๐ฎ ๐ต๐ฉ๐ฆ ๐ฐ๐ฑ๐ต๐ช๐ฐ๐ฏ ๐ฐ๐ง ๐ข ๐ค๐ถ๐ด๐ต๐ฐ๐ฎ ๐ฅ๐ข๐ต๐ฆ ๐ณ๐ข๐ฏ๐จ๐ฆ.
All done with ๐ฐ๐ฎ๐น๐ฐ๐๐น๐ฎ๐๐ถ๐ผ๐ป ๐ด๐ฟ๐ผ๐๐ฝ๐ ๐๐ผ ๐๐ต๐ฒ ๐ฟ๐ฒ๐๐ฐ๐๐ฒ and with some ๐๐๐ก๐ฉ๐๐ง๐จ
๐พ๐ง๐๐๐๐ฉ: If I remember correctly, I saw a trick on this custom date range slicer years ago from BI Elite!
Let DAX tell the story...
createOrReplace
table 'Date Slicer'
calculationGroup
precedence: 1
calculationItem 'Last 30 Days' =
VAR __Isdatesfiltered =
CALCULATE( ISFILTERED( 'Date'[Date] ), ALLSELECTED( ) )
VAR _Day = 30
VAR __Result =
IF(
__Isdatesfiltered,
SELECTEDMEASURE( ),
CALCULATE(
SELECTEDMEASURE( ),
KEEPFILTERS(
DATESINPERIOD( 'Date'[Date], TODAY( ), -_Day, DAY )
)
)
)
RETURN
__Result
calculationItem 'Last 3 Months' =
VAR __Isdatesfiltered =
CALCULATE( ISFILTERED( 'Date'[Date] ), ALLSELECTED( ) )
VAR _Day = 90
VAR __Result =
IF(
__Isdatesfiltered,
SELECTEDMEASURE( ),
CALCULATE(
SELECTEDMEASURE( ),
KEEPFILTERS(
DATESINPERIOD( 'Date'[Date], TODAY( ), -_Day, DAY )
)
)
)
RETURN
__Result
calculationItem 'Last 6 Months' =
VAR __Isdatesfiltered =
CALCULATE( ISFILTERED( 'Date'[Date] ), ALLSELECTED( ) )
VAR __Day = 180
VAR __Result =
IF(
__Isdatesfiltered,
SELECTEDMEASURE( ),
CALCULATE(
SELECTEDMEASURE( ),
KEEPFILTERS(
DATESINPERIOD( 'Date'[Date], TODAY( ), -__Day, DAY )
)
)
)
RETURN
__Result
calculationItem 'Current Year' =
VAR __Isdatesfiltered =
CALCULATE( ISFILTERED( 'Date'[Date] ), ALLSELECTED( ) )
VAR __Result =
IF(
__Isdatesfiltered,
SELECTEDMEASURE( ),
CALCULATE(
SELECTEDMEASURE( ),
KEEPFILTERS( DATESYTD( 'Date'[Date] ) )
)
)
RETURN
__Result
calculationItem 'Last Year' =
VAR __Isdatesfiltered =
CALCULATE( ISFILTERED( 'Date'[Date] ), ALLSELECTED( ) )
VAR __Result =
IF(
__Isdatesfiltered,
SELECTEDMEASURE( ),
CALCULATE(
SELECTEDMEASURE( ),
KEEPFILTERS(
SAMEPERIODLASTYEAR( DATESYTD( 'Date'[Date] ) )
)
)
)
RETURN
__Result
calculationItem All =
VAR __Isdatesfiltered =
CALCULATE( ISFILTERED( 'Date'[Date] ), ALLSELECTED( ) )
VAR __Result =
IF(
__Isdatesfiltered,
SELECTEDMEASURE( ),
CALCULATE(
SELECTEDMEASURE( ),
REMOVEFILTERS( 'Date'[Date] )
)
)
RETURN
__Result
calculationItem Custom =
VAR __Isdatesfiltered =
CALCULATE( ISFILTERED( 'Date'[Date] ), ALLSELECTED( ) )
VAR __Result =
IF(
__Isdatesfiltered,
SELECTEDMEASURE( ),
CALCULATE(
SELECTEDMEASURE( ),
REMOVEFILTERS( 'Date'[Date] )
)
)
RETURN
__Result
measure 'Date period' = MIN('Date'[Date]) & " - " & MAX('Date'[Date])
measure 'Filter Date Slicer Custom' = IF( SELECTEDVALUE ('Date Slicer'[Date slicer column] ) = "Custom", 1, 0 )
formatString: 0
measure 'Title Custom Date Slicer State' =
IF(
SELECTEDVALUE('Date Slicer'[Date slicer column]) = "Custom",
"Choose a custom date range",
"Custom selection disabled")
column 'Date slicer column'
dataType: string
sourceColumn: Name
sortByColumn: Ordinal
column Ordinal
dataType: int64
isHidden
sourceColumn: Ordinal