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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply

SWITCH FUNCTION not working for certain visuals for "Total Hours (Previous 30 Days)"

Hey,

 

I have a SWITCH fucntion that is working for everything but "Total Hours (Previous 30 Days)", I'm presuming this is due to the way I've written the DAX for this measure as opposed to the others, the problem is that when I select the "Total Hours (Previous 30 Days)" option, some of my visuals don't display (The ones that are linked to other tables), If I just load the measure on it's own, then it works, so it's something to do with the way I've written the DAX that is preventing me using other tables fo visualisation.

 

 

Measure Selection (Hours) =
SWITCH( TRUE(),
VALUES('Date Period'[Date Period]) = "This Month", TimeSheet[Total Hours (MTD)],
VALUES('Date Period'[Date Period]) = "Previous Month", TimeSheet[Total Hours (Previous Month)],
VALUES('Date Period'[Date Period]) = "Previous 30 Days", [Total Hours (Previous 30 Days)],
VALUES('Date Period'[Date Period]) = "Year To Date", TimeSheet[Total Hours (YTD)],
VALUES('Date Period'[Date Period]) = "Custom", TimeSheet[Total Hours],
BLANK())
 
 
Total Hours = SUM(TimeSheet[Hours])
 
 
Total Hours (Previous Month) = CALCULATE([Total Hours]
,DATEADD(DATESMTD(Dates[Date]) ,-1 ,MONTH ) )
 
 
Total Hours (Previous 30 Days) = CALCULATE([Total Hours],
FILTER(ALL(Dates),
Dates[Date] > MIN(Dates[Date]) - 30 &&
Dates[Date] < MIN(Dates[Date])))
 
 
All of the rest work, but when I try and use "Total Hours (Previous 30 Days)" I get a blank visual
 
Any help would be welcomed.
 
Thanks,
 
J
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@magnify-bi-com , Try like this

 

Rolling 30 = CALCULATE([Total Hours],DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-30,DAY))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@magnify-bi-com , Try like this

 

Rolling 30 = CALCULATE([Total Hours],DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-30,DAY))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks Amit, foolishly, I think I just needed to change my MINs to MAXs, that seems to have done the trick.

 

But your soltuion worked also.

 

Thanks,

 

Jon

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.