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

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

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

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