# How to have the units for energy show as kW h instead of h kW?

I observe the following in Wolfram Language:

Quantity[ 1, "Kilowatt hours" ] (* or "Kilowatts" * "Hours" *)

(* 1 h kW *)


That looks rather unconventional and in Wolfram Alpha it is done as kW h, for example: kW vs. kWh

How can this be achieved in Mathematica being compatible to the units framework?

EDIT:

Some more peculiarities.

Quantity[ 1, "Megawatt hours" ]
(* 1 h MW *)

(* but *)

Quantity[ 1, "USDollars" / "Megawatt hours" ]
(* Quantity: Unable to interpret unit specification *)


It is not the age of energy as of yet. ;-)

• it seems to be baked into the display by frontend. Compare Quantity[1, "Hours"*"Kilowatts"] and Quantity[1, "Kilowatts"*"Hours"] they both give 1 h kW May be it uses some internal ordering based on letters or something like that? Commented Mar 21, 2022 at 12:20
• I do not think there is a way to change that. One can try to use \$PrePrint to change the display, but it is tricky for this kind of output. Better learn to live with it :) You could submit request to WRI to change this and see what they say? Commented Mar 21, 2022 at 12:23
• Quantity[1, "USDollars"/("Kilowatts"*"Hours")] seems to solve your dollar issue. FYI, it seems to be sorting alphabetically by the unit name. Commented Mar 21, 2022 at 12:35
• @gwr It is a new kind of units :) Commented Mar 21, 2022 at 12:46
• If you are really desperate you could do Unprotect[RowBox]; RowBox[{"\"h\"", "\[ThinSpace]", "\"kW\""}] := RowBox[{"kWh"}]. But that is maybe not the right way to eat cookies. Commented Mar 21, 2022 at 12:59

QuantityUnitsPrivategetCompoundUnitBoxes@Quantity[_, "Hours" "Kilowatts"] :=
RowBox[{"\"kW\"", "\[ThinSpace]", "\"h\""}]

QuantityUnitsPrivategetCompoundUnitBoxes@Quantity[_, _/("Hours" "Kilowatts")] :=
RowBox[{"\"per\"", "\"kW\"", "\[ThinSpace]", "\"h\""}]


## Update for Version 14 or Earlier

At least since version 14, the design of Quantity seems to be changed. Now we need the following code instead:

QuantityUnitsPrivategetCompoundUnitBoxes["Hours" "Kilowatts"] :=
RowBox[{"\"kW\"", "\[ThinSpace]", "\"h\""}]

QuantityUnitsPrivateToNDBoxes[{}, {"Hours", "Kilowatts"}] :=
RowBox[{"\"per\"", "\"kW\"", "\[ThinSpace]", "\"h\""}]

• It seems that this is not working anymore as of v14?
– gwr
Commented Mar 11 at 14:58
• @gwr Luckily it's not too hard to fix. See my update :) . Commented Mar 11 at 16:36