Trouble showing Decimal Value - Still getting 0

Iโ€™m having trouble displaying a decimal result from the formula below after using Steveโ€™s Tip. I have all expressions wrapped in the 1.0 to indicate decimal but Iโ€™m not sure what Iโ€™m missing. Whatโ€™s interesting is the correct value will flash on the screen quickly but then revert to 0)

vir_sum_whrs (datatype=Decimal):
IF(
SUM(SELECT(Receiving Work Hours[vir_work_hrs],[receiving_id]=[_THISROW].[receiving_id]))<0,
0,
(SUM(SELECT(Receiving Work Hours[vir_work_hrs],[receiving_id]=[_THISROW].[receiving_id])))*1.0
)


Solved Solved
0 4 317
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

Your vir_sum_wkhrs expression, formatted to my preference:

IF(
  (
    SUM(
      SELECT(
        Receiving Work Hours[vir_work_hrs],
        ([receiving_id] = [_THISROW].[receiving_id])
      )
    )
    < 0
  ),
  0,
  (
    (
      SUM(
        SELECT(
          Receiving Work Hours[vir_work_hrs],
          ([receiving_id] = [_THISROW].[receiving_id])
        )
      )
    )
    * 1.0
  )
)

Another, more efficient way to do it:

MAX(
  LIST(
    0.0,
    SUM(
      SELECT(
        Receiving Work Hours[vir_work_hrs],
        ([receiving_id] = [_THISROW].[receiving_id])
      )
    )
  )
)

Expression for vir_work_hrs:

(((((HOUR([Work Hours]) * 60) + MINUTE([Work Hours])) / 60)) * 1.0)

HOUR(...) gives Number.

number * 60 gives Number.

MINUTE(...) gives Number.

number + number gives Number.

number / 60 gives Number. Fractional component is lost!

number * 1.0 gives Decimal, essentially by appending .0 to the Number value.

Try instead:

(((HOUR([Work Hours]) * 60) + MINUTE([Work Hours])) / 60.0)

I.e., divide by 60.0 (Decimal) rather than 60 (Number).

Or just:

TOTALHOURS([Work Hours])

See also:

View solution in original post

4 REPLIES 4

Steve
Platinum 4
Platinum 4

Your vir_sum_wkhrs expression, formatted to my preference:

IF(
  (
    SUM(
      SELECT(
        Receiving Work Hours[vir_work_hrs],
        ([receiving_id] = [_THISROW].[receiving_id])
      )
    )
    < 0
  ),
  0,
  (
    (
      SUM(
        SELECT(
          Receiving Work Hours[vir_work_hrs],
          ([receiving_id] = [_THISROW].[receiving_id])
        )
      )
    )
    * 1.0
  )
)

Another, more efficient way to do it:

MAX(
  LIST(
    0.0,
    SUM(
      SELECT(
        Receiving Work Hours[vir_work_hrs],
        ([receiving_id] = [_THISROW].[receiving_id])
      )
    )
  )
)

Expression for vir_work_hrs:

(((((HOUR([Work Hours]) * 60) + MINUTE([Work Hours])) / 60)) * 1.0)

HOUR(...) gives Number.

number * 60 gives Number.

MINUTE(...) gives Number.

number + number gives Number.

number / 60 gives Number. Fractional component is lost!

number * 1.0 gives Decimal, essentially by appending .0 to the Number value.

Try instead:

(((HOUR([Work Hours]) * 60) + MINUTE([Work Hours])) / 60.0)

I.e., divide by 60.0 (Decimal) rather than 60 (Number).

Or just:

TOTALHOURS([Work Hours])

See also:

Thanks Steve! Will give it a go and report back!

Hi Steve, no luck.

Changed the vir_work_hrs:
3X_1_b_1bb8412e0d8f725aab9abba1365fa507bb931845.png

Changed vir_sum_hrs to
IF(
(
SUM(
SELECT(
Receiving Work Hours[vir_work_hrs],
([receiving_id] = [_THISROW].[receiving_id])
)
)
< 0
),
0,
(
(
SUM(
SELECT(
Receiving Work Hours[vir_work_hrs],
([receiving_id] = [_THISROW].[receiving_id])
)
)
)
* 1.0
)
)
3X_3_6_36b95188cd5d62fc0627a849620152c81f750eba.png

Sorry Steve, looks like weโ€™re all set. System just didnโ€™t save the change. Thanks so much!
3X_a_7_a759bf155098d14f3521edaf72fab2ead09e9980.png

Top Labels in this Space