Forum Discussion

h4tt3n's avatar
h4tt3n
Helper V
6 years ago
Solved

Multiple global constants best practices?

Hello folks,   Experienced programmer but Powert Query / DAX beginner here. I need to somehow define and manage a number of global constants in my Power BI workspace and would like your suggestions...
  • Jimmy801's avatar
    Jimmy801
    6 years ago

    Hello h4tt3n 

     

    sorry, here I can't e of any help. But maybe there are some possibilities out there. Maybe someone else can help. You can also think of posting in the DAX-section of this forum.

    What you can do for sure due is to create a datatable with power query and then hand over this data into DAX and access there. What do you think of that? Here an example

    1. Create query called "Constants" with datatable like this

    let
        Constants= #table(type table [ConstantName=  text, ConstantValue=  any ], {{"ConstantA",1}, {"ConstantB", 2}})
    in
        Constants

     2. Create a Measure that reads one constant like this

    ConstantA = LOOKUPVALUE(Constants[ConstantValue];Constants[ConstantName];"ConstantA")

     3. Use this measure in your environment (here in a new column)

    ConstantA = LOOKUPVALUE(Constants[ConstantValue];Constants[ConstantName];"ConstantA")

     4. External reference would then look like this

    Column = Constants[ConstantA]

     

    What do you think of this solution?


    If this post helps or solves your problem, please mark it as solution.
    Kudos are nice to - thanks
    Have fun

    Jimmy