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 IV
Super User IV

@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!

Proud to be a Super User!

Website   YouTube    LinkedIn

View solution in original post

3 REPLIES 3
Fowmy
Super User IV
Super User IV

@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!

Proud to be a Super User!

Website   YouTube    LinkedIn

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!

Proud to be a Super User!

Website   YouTube    LinkedIn

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Top Solution Authors
Top Kudoed Authors