cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hwr7dd
Frequent Visitor

DAX Date Filter Issue

Hello,
I have data setup like so:

DateidUsableAvailable
4/1/20211302
4/1/2021212321
4/2/202111334
4/2/2021216123
4/3/2021112324

and so on. It is connected on a many to one relationship to a date dimension table called date_dimension
I am trying to get Occupancy by this DAX Measure:

 

occupancy =
CALCULATE (
    (
        1
            - (
                SUM ( 'Table'[Available] )
                    / SUM ( 'Table'[Usable] )
            )
    ),
    DATESBETWEEN (
        Date_Dimension[Date],
        MIN ( Date_Dimension[Date] ),
        MAX ( Date_Dimension[Date] )
    )
)

 

 

 

 

 

This works OK without any date filters applied, but if I apply a date filter I get this kind of behavior:hwr7dd_0-1620507003544.png

In this example I set a date filter 30 days prior to apr 22 2021. I guess I'm not understanding why the filter isn't passed to occupancy when both available and usable are both filtered correctly. You can't tell from that graph but during the period that it's supposed to be calculating it does calculate the correct value, but when its in a period that is not intended (in this case any date no 30 days prior to apr 22 2021) it defaults to 100%. Also note, I want the user to be able to see aggregate by day info or they could possibly see by a particular id by day based on whether they use a slicer or not. 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@hwr7dd 

Please try the following formula:

occupancy = 
var __available =  SUM(Table7[Available])
var __usable =  SUM(Table7[Usable])
var __result = 
IF(
    __available <> BLANK() && __usable <> BLANK(),   
        1-
        DIVIDE(
            SUM(Table7[Available]),
            SUM(Table7[Usable])
        )
    )
return
    __result

Fowmy_0-1620517356593.png

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@hwr7dd 

Please try the following formula:

occupancy = 
var __available =  SUM(Table7[Available])
var __usable =  SUM(Table7[Usable])
var __result = 
IF(
    __available <> BLANK() && __usable <> BLANK(),   
        1-
        DIVIDE(
            SUM(Table7[Available]),
            SUM(Table7[Usable])
        )
    )
return
    __result

Fowmy_0-1620517356593.png

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

hwr7dd
Frequent Visitor

@Fowmy Fowmy,

I used a modified version of your solution. I'd like to understand why the if statement is required in this case. if possible

@hwr7dd 

 

Wirhout the IF statement, it will show 100% when there is no data in your table as you use 1-

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!