cancel
Showing results 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.

Helper II

## Calculation giving the same value against every row

Hello,

I want to calculate the total Up Time on the basis of "Hours Of Operational Use". I have written the below DAX measure for the same.

vTotalUptime = IF(MAX('Service Availability'[Hours Of Operational Use])="24x7",[vTotalDaysInPeriod]*24*60,
IF(MAX('Service Availability'[Hours Of Operational Use])="Extended Hours - 7 days",[vTotalDaysInPeriod]*13*60,
IF(MAX('Service Availability'[Hours Of Operational Use])="Extended Hours - 5 days",[vBusinessDaysInPeriod]*13*60,""))))

However, the output is giving me the same value against every row which is not correct.
The output is correct only for the first row i.e. 31*24*60 = 44640
However, 2nd row should give me the value as 540 i.e. 1*9*60 = 540. Similarly 3rd row should show 1*13*60 =780 & 4th row should show 31*13*60 = 24180
Can someone please highlight what have I done wrong above.

Thanks.

1 ACCEPTED SOLUTION
Helper II

Thanks @tamerj1  for your time and effort to get this calculation correct.

What I discovered later is that the problem was not with the DAX witten by me. I was making use of column 'Hours of Operational Use' from wrong table which was causing this problem. After changing the table, the same DAX started giving the correct output. Please see below snapshot.

But I must admit that your modified DAX version is simple and easy to understand.

Thanks Again for your quick help. Much appreciated. Cheers.

4 REPLIES 4
Super User

HI @vishu263
Apparently you have created a calculated column instead of a measure. Just use the same DAX in a measure and it should wok. However, here is an improved version of the DAX

``````vTotalUptime =
VAR Days = [vTotalDaysInPeriod]
RETURN
SUMX (
VALUES ( 'Service Availability'[Hours Of Operational Use] ),
SWITCH (
'Service Availability'[Hours Of Operational Use],
"24x7",
Days * 24 * 60,
"Extended Hours - 7 days",
Days * 13 * 60,
"Extended Hours - 5 days",
)
)``````

Make sure [vTotalDaysInPeriod] and [vTotalDaysInPeriod] are also measures not calculated columns. Please let me know if they are in fact columns in the source data table.

Helper II

Thanks @tamerj1  for your time and effort to get this calculation correct.

What I discovered later is that the problem was not with the DAX witten by me. I was making use of column 'Hours of Operational Use' from wrong table which was causing this problem. After changing the table, the same DAX started giving the correct output. Please see below snapshot.

But I must admit that your modified DAX version is simple and easy to understand.

Thanks Again for your quick help. Much appreciated. Cheers.

Super User

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
vTotalUptime =
VAR _selected_value =
SELECTEDVALUE ( Sheet3[Hours Of Operational Use] )
VAR _totaldaysinperiod =
SELECTEDVALUE ( Sheet3[vTotalDaysInPeriod] )
VAR _factor_hours_9 = 9
VAR _factor_hours_13 = 13
VAR _factor_hours_24 = 24
VAR _factor_minutes = 60
RETURN
IF (
_selected_value = "24x7",
_totaldaysinperiod * _factor_hours_24 * _factor_minutes,
IF (
IF (
_selected_value = "Extended Hours - 7 days",
_totaldaysinperiod * _factor_hours_13 * _factor_minutes,
IF (
_selected_value = "Extended Hours - 5 days",
)
)
)
)

Proud to be a Super User!

Helper II

Thanks @some_bih for your time and effort to get this calculation correct. I am sure the above calculation will give the desired output.

What I discovered later is that I was making use of column 'Hours of Operational Use' from wrong table which was causing this problem. After changing the table, the same DAX started giving the correct output.

Thanks Again.

Announcements

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

#### Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

#### Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors