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
sumanchintala19
Frequent Visitor

Rolling 3 , 6 , 12 and Past months slicer


 Hello All, 
 
I am encountering the below scenarios , kindly assist if you could.
 
I have a period slicer which shows Rolling 3 , 6 , 12 and Past months  where users can select the slicer selection accordingly. 

Rolling 3 month = 
IFERROR(CALCULATE(SUM(FACT[TERMINATIONS]), FILTER (CALENDAR_TABLE,CALENDAR_TABLE[ISLAST12MONTH]="Y")) / [AVG HEADCOUNT FOR 3 MONTHS],BLANK())
 
Rolling 6 month = 
IFERROR(CALCULATE(SUM(FACT[TERMINATIONS]), FILTER (CALENDAR_TABLE,CALENDAR_TABLE[ISLAST12MONTH]="Y")) / [AVG HEADCOUNT FOR 6 MONTHS],BLANK())
 
Rolling 12 month = 
IFERROR(CALCULATE(SUM(FACT[TERMINATIONS]), FILTER (CALENDAR_TABLE,CALENDAR_TABLE[ISLAST12MONTH]="Y")) / [AVG HEADCOUNT FOR 12 MONTHS],BLANK())
 
Past month = 
IFERROR(CALCULATE(SUM(FACT[TERMINATIONS]), FILTER (CALENDAR_TABLE,CALENDAR_TABLE[ISLAST12MONTH]="N")) / [AVG HEADCOUNT FOR 12 MONTHS],BLANK())
 
Turnover% = Switch ( selectedvalue(period[period]),
"Rolling 3" ,Rolling 3 month,
"Rolling 6" ,Rolling 6 month,
"Rolling 12" ,Rolling 12 month,
"Past month" ,Past month)
 
Now am trying to show latest month values on the visual . the mesure defined as below. 
latest selected turnover% = 
VAR maxdate = max(CALENDAR_TABLE[MONTH])
RETURN
CALCULATE ( Turnover%),
CALENDAR_TABLE[MONTH] = maxdate) 
 
latest selected turnover% is begun to be used on the visual on the report page . 
Those are the merics which drive my entire visuals . Based on the users period slicer selection I am able to display the mesure on the visual accordingly . 
Rolling 3, 6 and 12 months measures are working as we are expecting but when i select the past month slicer values the visual is not returning any values hence the visual is blank. 
 
Note : Past month means I wanted to display the before rolling 12 months data on the visual. 
period  table is a standalone table where i created on the power BI desktop for slicer only . 
 
I would appreciate it if you could help me on this issue.  
  
2 REPLIES 2
sumanchintala19
Frequent Visitor

 Thanks for your response . The issue with my dax function is at the end of the final dax I am trying to show only max month data . 

example: If the user selects "Past months" slicer the visual should show only latest month data on the visulas. 

Let's say in the " Past Month" slicer if it's a month like from jan 2021 to Dec 2022 , the dax has to show only for max month values which is Dec 22 . 

amitchandak
Super User
Super User

@sumanchintala19 , You can try like

 

https://medium.com/chandakamit/power-bi-when-i-felt-lazy-and-i-needed-too-many-measures-ed8de20d9f79

 

refer

Switch Period =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min =
SWITCH(SELECTEDVALUE(Period[PeriodType],"MTD"),
"YTD",eomonth(_max,-1*MONTH(_max))+1 , //FY April -March
"FYTD",if( Month(_max) <4 , date(year(_max)-1,4,1) ,date(year(_max),4,1)), //FY April -March
"QTD",eomonth(_max,-1* if( mod(Month(_max),3) =0,3,mod(Month(_max),3)))+1,
"MTD",eomonth(_max,-1)+1 ,
"WTD", _max -WEEKDAY(_max,2)+1,
"Cumm", Minx(ALLSELECTED('Date'),'Date'[Date]),
"Rolling 3", date(Year(_max), month(_max) -3, Day(_max))+1,
"Rolling 6", date(Year(_max), month(_max) -6, Day(_max))+1,
"Rolling 12", date(Year(_max), month(_max) -12, Day(_max))+1,
BLANK())
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

 

or

 

Switch Period =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max =
SWITCH(SELECTEDVALUE(Period[PeriodType],"MTD"),
"YTD",_max1,
"FYTD",_max1,
"QTD",_max1,
"MTD",_max1,
"This Month",eomonth(_max,0),
"LMTD",date(Year(_max), month(_max) -1, Day(_max)),
"Last Month",eomonth(_max,-1),
"WTD", _max1,
"Cumm",_max1,
"Rolling 3", _max1,
"Rolling 6", _max1,
"Rolling 12",_max1,
"Rolling 7 Day",_max1,
"Yesterday",_max1-1,
BLANK())

var _min =
SWITCH(SELECTEDVALUE(Period[PeriodType],"MTD"),
"YTD",eomonth(_max,-1*MONTH(_max))+1 , //FY April -March
"FYTD",if( Month(_max) <4 , date(year(_max)-1,4,1) ,date(year(_max),4,1)), //FY April -March
"QTD",eomonth(_max,-1* if( mod(Month(_max),3) =0,3,mod(Month(_max),3)))+1,
"MTD",eomonth(_max,-1)+1 ,
"This Month",eomonth(_max,-1)+1 ,
"LMTD",eomonth(_max,-1)+1,
"Last Month",eomonth(_max,-1)+1,
"WTD", _max -WEEKDAY(_max,2)+1,
"Cumm", Minx(ALLSELECTED('Date'),'Date'[Date]),
"Rolling 3", date(Year(_max), month(_max) -3, Day(_max))+1,
"Rolling 6", date(Year(_max), month(_max) -6, Day(_max))+1,
"Rolling 12", date(Year(_max), month(_max) -12, Day(_max))+1,
"Rolling 7 Day", date(Year(_max), month(_max) , Day(_max)-7),
"Yesterday",_max1-1
BLANK())
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

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.

Top Solution Authors