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
vishu263
Helper II
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])="Business Hours",[vBusinessDaysInPeriod]*9*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. 
Capture.PNG
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

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. 

Capture.PNG

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

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

View solution in original post

4 REPLIES 4
tamerj1
Super User
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]
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.

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. 

Capture.PNG

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

Hi @vishu263  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 = 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 (
            _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
                )
            )
        )
    )

some_bih_0-1687760579894.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






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. 

Capture.PNG

Thanks Again.

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.

Top Solution Authors