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

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