Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Uhan1101
Frequent Visitor

Date hierachy for yesterday, last 7 days, last month and this month

Hi

I'm trying to make a filter hierachy so the user can choose between data from yesterday, the last 7 days, last month, this mont and year to date. I've tried with both SWITCH and IF, but in both cases not all data will included. For the last 7 days shows the last days but without yesterday and this month is without yesterday and the last 7 days

 

My formula looks like this

 

Hieraki = SWITCH(
TRUE();
 
'Calendar'[Måned]=MONTH(TODAY())-1;"Forrige måned";
'Calendar'[Måned]=MONTH(TODAY());"Denne måned";
'Calendar'[Date]=today()-1;"Igår";
'Calendar'[Date]>=(TODAY()-8)&&'Calendar'[Date]<TODAY();"7 dage"
)
 or this
Tidshieraki =
if('Calendar'[Date]=today()-1;"Igår";
if('Calendar'[Date]>=(TODAY()-8)&&'Calendar'[Date]<TODAY();"7 dage";

if('Calendar'[Måned]=MONTH(TODAY())-1;"Forrige måned";
if('Calendar'[Date]<=(today()-1);"År-til-dato";

if('Calendar'[Måned]=MONTH(TODAY());"Denne måned";
"andet"
)))))
 
Can anybody help me?
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Uhan1101 , With a period slicer try like

 

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))

 

 

refer to more details on

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

 

Field parameter is another option, you need to have all measure

https://medium.com/@amitchandak/power-bi-field-parameters-a-quick-way-for-dynamic-visuals-fc4095ae9a...

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Uhan1101 , With a period slicer try like

 

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))

 

 

refer to more details on

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

 

Field parameter is another option, you need to have all measure

https://medium.com/@amitchandak/power-bi-field-parameters-a-quick-way-for-dynamic-visuals-fc4095ae9a...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors