cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors