Forum Discussion

masplin's avatar
masplin
Icon for Impactful Individual rankImpactful Individual
28 days ago
Solved

Create multiple calculation items of similar format using a table input?

 

I should have asked this question earlier. i have created a whole load of calculation items with same structure, but different measure names. For example. I have disconnected table containing Actual, Budget, Variance

#FTE
IF(MAX(ABV[ABV])="Actual",[FTE Purchased per Client (Bill ex Canc)],

IF(MAX(ABV[ABV])="Budget",'Budget Summary'[Budget FTE per Client],

[vs Budget FTE per Client]))

% Client Utilisation
IF(MAX(ABV[ABV])="Actual",[Utilisation Client % Intro], 

IF(MAX(ABV[ABV])="Budget", [Budget Utilisation Client % Intro],

 [vs Budget Utilisation Client % Intro]))

Could I have created a single calculation item and made a table listing the measures needed for each item? Maybe some sort of SWITCH statement? Be much easier to manage as have about 30 now and growing. 

IF(MAX(ABV[ABV])="Actual",[Column 1],

 IF(MAX(ABV[ABV])="Budget", [Column 2],

 [Column 3]))

 

Thanks

  • masplin's avatar
    masplin
    22 days ago

    I didnt have time to learn about TDML, but will do when I have time.

    What I did instead was this
     The report I was building had a custom hierarchy so I was using this table to lay out the report

     

    In order to pick up the right measure for each Key Result I already had this switch measure

    Selected Measure Value =  SWITCH(     SELECTEDVALUE('Scorecard'[KEY RESULT]),     "# Enquiries", [Enquiry Count],     "# Qualified Enquiries", [Qualified Enquiry Count],     "# SQLs", [SQL Count],

    So I created 2 more measures one for budget and one for vs budget

    Selected Budget Value =  SWITCH(     SELECTEDVALUE('Scorecard'[KEY RESULT]),     "# Enquiries", BLANK(),     "# Qualified Enquiries", BLANK(),     "# SQLs", [Budget SQL],
    Selected vs Budget Value =  SWITCH(     SELECTEDVALUE('Scorecard'[KEY RESULT]),     "# Enquiries", BLANK(),     "# Qualified Enquiries", BLANK(),     "# SQLs", [SQL vs Budget],

    Then I just need one calculation item

    IF(MAX(ABV[ABV])="Actual",[Selected Measure Value], IF(MAX(ABV[ABV])="Budget",[Selected Budget Value], IF([Selected Budget Value]=BLANK(),BLANK(),[Selected vs Budget Value])))

    The advantage of this is writing the measures in pbix you get the measure prompts so you pick the right one, whereas doing it in tabular editor you have to write long hand and easy to make a mistake.  Easier to manage than 30 calculation items.

    Think this was quite a good solution, but not as good as just being to create a table of al lthe measures listed in the 3 "selected" measures.

     

    Appreciate the responses

6 Replies

  • ShahRukhSameer's avatar
    ShahRukhSameer
    Icon for Continued Contributor rankContinued Contributor

    Hi masplin​,

    Yes, you can simplify the pattern, but there is one limitation: DAX can't take a measure name stored as text in a table and then dynamically evaluate that measure.

    You could use one calculation item with a SWITCH, for example:

    SWITCH(
    SELECTEDVALUE(ABV[ABV]),
    "Actual", [FTE Purchased per Client (Bill ex Canc)],
    "Budget", [Budget FTE per Client],
    [vs Budget FTE per Client]
    )

    The problem is that you'd still have to specify the three measures for each calculation item, so with 30+ measures it doesn't completely solve the maintenance issue.

    Your disconnected ABV table is a perfectly reasonable approach. Unfortunately, there isn't a simple DAX equivalent of "look up the measure name from this table and evaluate it".

    If you have a lot of these and they're following exactly the same pattern, I'd probably look at restructuring the calculation group rather than creating 30 separate calculation items. That could make it much easier to maintain going forward.

  • Hello masplin​,

    Yes, SWITCH can replace the nested IF here:

    SWITCH(
        SELECTEDVALUE(ABV[ABV]),
        "Actual", [FTE Purchased per Client (Bill ex Canc)],
        "Budget", [Budget FTE per Client],
        [vs Budget FTE per Client]
    )

    The three measure references would still need to be specified for each calculation item.

    You could also look at SELECTEDMEASURE() if the calculation group can be structured so the same logic applies to the measure in context.

  • ShivekMaharaj's avatar
    ShivekMaharaj
    Icon for Memorable Member rankMemorable Member

    Hi masplin​,

    The SWITCH suggestions above are valid, but there is a newer option that could make this much easier to maintain.

    Since June 2026, Power BI supports DAX user-defined functions as a GA feature. They let you package repeated parameterized DAX logic once and then call it from measures/calculation items.

    For example, you could define something along these lines:

    FUNCTION PickABV = (     ActualValue,     BudgetValue,     VarianceValue ) =>     SWITCH(         SELECTEDVALUE(ABV[ABV]),         "Actual", ActualValue,         "Budget", BudgetValue,         VarianceValue     )

    Then each calculation item becomes much smaller:

    PickABV(     [FTE Purchased per Client (Bill exc Canc)],     [Budget FTE per Client],     [vs Budget FTE per Client] )

    and similarly for Utilisation, Margin, etc.

    You would still need to specify the three actual measure references for each calculation item. A disconnected table can't dynamically turn a measure name stored as text into a model measure reference.

    For the other part of the problem, creating 30 calculation items, I would look at TMDL view rather than creating them manually. Microsoft supports creating and editing calculation groups through TMDL, so you can script the calculation-group metadata and generate the item definitions from your mapping rather than maintaining 30 items through the UI.

    So I would separate it into:

    • UDF = remove the repeated Actual/Budget/Variance logic
    • TMDL = automate/generate the 30 calculation-item definitions


    That still keeps explicit measure references, but it should make the model considerably easier to maintain.

    AI-assisted drafting: AI was used to help structure and phrase this response. I reviewed and validated the technical content before posting.

    • masplin's avatar
      masplin
      Icon for Impactful Individual rankImpactful Individual

      I didnt have time to learn about TDML, but will do when I have time.

      What I did instead was this
       The report I was building had a custom hierarchy so I was using this table to lay out the report

       

      In order to pick up the right measure for each Key Result I already had this switch measure

      Selected Measure Value =  SWITCH(     SELECTEDVALUE('Scorecard'[KEY RESULT]),     "# Enquiries", [Enquiry Count],     "# Qualified Enquiries", [Qualified Enquiry Count],     "# SQLs", [SQL Count],

      So I created 2 more measures one for budget and one for vs budget

      Selected Budget Value =  SWITCH(     SELECTEDVALUE('Scorecard'[KEY RESULT]),     "# Enquiries", BLANK(),     "# Qualified Enquiries", BLANK(),     "# SQLs", [Budget SQL],
      Selected vs Budget Value =  SWITCH(     SELECTEDVALUE('Scorecard'[KEY RESULT]),     "# Enquiries", BLANK(),     "# Qualified Enquiries", BLANK(),     "# SQLs", [SQL vs Budget],

      Then I just need one calculation item

      IF(MAX(ABV[ABV])="Actual",[Selected Measure Value], IF(MAX(ABV[ABV])="Budget",[Selected Budget Value], IF([Selected Budget Value]=BLANK(),BLANK(),[Selected vs Budget Value])))

      The advantage of this is writing the measures in pbix you get the measure prompts so you pick the right one, whereas doing it in tabular editor you have to write long hand and easy to make a mistake.  Easier to manage than 30 calculation items.

      Think this was quite a good solution, but not as good as just being to create a table of al lthe measures listed in the 3 "selected" measures.

       

      Appreciate the responses

    • masplin's avatar
      masplin
      Icon for Impactful Individual rankImpactful Individual

      seems I would need to learn some coding to write a script to spit out all the different calculation items for the TMDL to read?  Bit beyond my coding ability!!! 

  • Hi masplin​ 

    As suggested by ShivekMaharaj​  explore UDF.

    Another option worth exploring is calculation group.

    https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-user-defined-functions-overview

    https://learn.microsoft.com/en-us/analysis-services/tabular-models/calculation-groups?view=sql-analysis-services-2025

    Please give kudos or mark it as solution once confirmed.

    Thanks and Regards,

    Praful