Forum Discussion
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.
- Anonymous3 years ago
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
- tamerj1
Community Champion
HI Anonymous
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 DAXvTotalUptime = VAR Days = [vTotalDaysInPeriod] VAR BusinessDays = [vBusinessDaysInPeriod] RETURN SUMX ( VALUES ( 'Service Availability'[Hours Of Operational Use] ), SWITCH ( 'Service Availability'[Hours Of Operational Use], "24x7", Days * 24 * 60, "Business Hours", BusinessDays * 9 * 60, "Extended Hours - 7 days", Days * 13 * 60, "Extended Hours - 5 days", BusinessDays * 13 * 60 ) )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.
- AnonymousNot applicable
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.
- some_bih
Community Champion
Hi Anonymous your measure vTotalUptime, could be as shown belos adjust Sheet3 to your table name
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 _businessdaysinperiod =SELECTEDVALUE ( Sheet3[vBusinessDaysInPeriod] )VAR _factor_hours_9 = 9VAR _factor_hours_13 = 13VAR _factor_hours_24 = 24VAR _factor_minutes = 60RETURNIF (_selected_value = "24x7",_totaldaysinperiod * _factor_hours_24 * _factor_minutes,IF (_selected_value = "Business Hours",_businessdaysinperiod * _factor_hours_9 * _factor_minutes,IF (_selected_value = "Extended Hours - 7 days",_totaldaysinperiod * _factor_hours_13 * _factor_minutes,IF (_selected_value = "Extended Hours - 5 days",_businessdaysinperiod * _factor_hours_13 * _factor_minutes))))- AnonymousNot applicable
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.