Forum Discussion
Help with Calculation Groups
- 16 days ago
Hi ramnikb,
Yes, this is a textbook calculation group use case. And since KG to LBS is a fixed factor, you can go one step further: keep only the KG measures and let one calculation item do the conversion. That removes the duplicate LBS measures instead of wrapping them in SWITCH.
table "Unit" (calculation group, column "Unit") item "KG" -> SELECTEDMEASURE() (ordinal 0, the default) item "LBS" -> SELECTEDMEASURE() * 2.20462 (only for volume measures) slicer on Unit[Unit], single select -> every volume measure followsThe important part is to scope the conversion, so revenue, prices and % measures pass through untouched:
-- Calculation item: LBS VAR IsVolume = ISSELECTEDMEASURE ( [Invoiced Volume], [Forecast Volume], [Budget Volume] ) -- or by naming convention: -- CONTAINSSTRING ( SELECTEDMEASURENAME (), "Volume" ) RETURN IF ( IsVolume, SELECTEDMEASURE () * 2.20462, SELECTEDMEASURE () ) -- Format String Expression on the LBS item (optional unit label) IF ( CONTAINSSTRING ( SELECTEDMEASURENAME (), "Volume" ), "#,0 \"lbs\"", SELECTEDMEASUREFORMATSTRING () )If some LBS measures aren't a straight conversion (rounding rules, different source columns), map them explicitly instead of multiplying:
-- Calculation item: LBS (mapping variant) SWITCH ( SELECTEDMEASURENAME (), "Invoiced Volume KG", [Invoiced Volume LBS], "Forecast Volume KG", [Forecast Volume LBS], SELECTEDMEASURE () )A few practical notes for an AS model:
compatibility level 1500+ is required for calculation groups author it in Tabular Editor or Visual Studio, then deploy if you also add time intelligence groups, set Precedence -> the unit conversion should apply after YTD/PY logic no slicer selection (or several items selected) -> no item is applied -> measures fall back to plain KG; use a single-select slicer hide the old *_LBS measures from report authors once migratedSo my overall approach would be:
one "Unit" calculation group: KG (passthrough) + LBS (x 2.20462) -> scope with ISSELECTEDMEASURE / name convention -> optional format string expression for the unit suffix -> single-select slicer -> retire the duplicate LBS measuresAI-assisted drafting: AI was used to help structure and phrase this response. I reviewed and validated the technical content before posting.
Hi ramnikb,
Yes, this is a textbook calculation group use case. And since KG to LBS is a fixed factor, you can go one step further: keep only the KG measures and let one calculation item do the conversion. That removes the duplicate LBS measures instead of wrapping them in SWITCH.
table "Unit" (calculation group, column "Unit")
item "KG" -> SELECTEDMEASURE() (ordinal 0, the default)
item "LBS" -> SELECTEDMEASURE() * 2.20462 (only for volume measures)
slicer on Unit[Unit], single select -> every volume measure followsThe important part is to scope the conversion, so revenue, prices and % measures pass through untouched:
-- Calculation item: LBS
VAR IsVolume =
ISSELECTEDMEASURE (
[Invoiced Volume],
[Forecast Volume],
[Budget Volume]
)
-- or by naming convention:
-- CONTAINSSTRING ( SELECTEDMEASURENAME (), "Volume" )
RETURN
IF ( IsVolume, SELECTEDMEASURE () * 2.20462, SELECTEDMEASURE () )
-- Format String Expression on the LBS item (optional unit label)
IF ( CONTAINSSTRING ( SELECTEDMEASURENAME (), "Volume" ),
"#,0 \"lbs\"", SELECTEDMEASUREFORMATSTRING () )If some LBS measures aren't a straight conversion (rounding rules, different source columns), map them explicitly instead of multiplying:
-- Calculation item: LBS (mapping variant)
SWITCH (
SELECTEDMEASURENAME (),
"Invoiced Volume KG", [Invoiced Volume LBS],
"Forecast Volume KG", [Forecast Volume LBS],
SELECTEDMEASURE ()
)A few practical notes for an AS model:
compatibility level 1500+ is required for calculation groups
author it in Tabular Editor or Visual Studio, then deploy
if you also add time intelligence groups, set Precedence
-> the unit conversion should apply after YTD/PY logic
no slicer selection (or several items selected) -> no item is applied
-> measures fall back to plain KG; use a single-select slicer
hide the old *_LBS measures from report authors once migratedSo my overall approach would be:
one "Unit" calculation group: KG (passthrough) + LBS (x 2.20462)
-> scope with ISSELECTEDMEASURE / name convention
-> optional format string expression for the unit suffix
-> single-select slicer -> retire the duplicate LBS measuresAI-assisted drafting: AI was used to help structure and phrase this response. I reviewed and validated the technical content before posting.