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.
Hello,
I have data setup like so:
Date | id | Usable | Available |
4/1/2021 | 1 | 30 | 2 |
4/1/2021 | 2 | 123 | 21 |
4/2/2021 | 1 | 133 | 4 |
4/2/2021 | 2 | 161 | 23 |
4/3/2021 | 1 | 123 | 24 |
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:
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.
Solved! Go to Solution.
@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
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@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
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@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
Wirhout the IF statement, it will show 100% when there is no data in your table as you use 1-
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |