Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Create a Measure from Field Parameters

I'm new to field parameters and am trying to see if this is possible. I have two field parameter lists that are simply listing various explicit measures I've created to provide counts of values from different columns in my table.

Numerator = {
    ("Count of A", NAMEOF('Table'[Count of A]), 0),
    ("Count of B", NAMEOF('Table'[Count of B]), 1),
    ("Count of C", NAMEOF('Table'[Count of C]), 2)
}
 
Denominator = {
    ("Count of A", NAMEOF('Table'[Count of A]), 0),
    ("Count of B", NAMEOF('Table'[Count of B]), 1),
    ("Count of C", NAMEOF('Table'[Count of C]), 2)
}
 
I want to create a new measure that calculates the division of the selected numerator by the selected denominator. This didn't work:
Measure = CALCULATE(
                DIVIDE(
                        SELECTEDVALUE(Numerator[Numerator]),
                        SELECTEDVALUE(Denominator[Denominator])
                        )
                    )
Is what I'm trying to do possible?
  • Anonymous I don't think this is going to work, in your measure you need to check which option is selected and then use the switch/if function to use the respective measure based on the selected value. check this post on how to get the selected value Using SELECTEDVALUE with Fields Parameters in Power BI - SQLBI

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

3 Replies

  • Anonymous I don't think this is going to work, in your measure you need to check which option is selected and then use the switch/if function to use the respective measure based on the selected value. check this post on how to get the selected value Using SELECTEDVALUE with Fields Parameters in Power BI - SQLBI

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

  • Zihang98's avatar
    Zihang98
    Regular Visitor

    I met very similar problem with you. What I did at the end is:

     

    Under each field parameters, you have three columns, Name, Fields, Order. We can't use the Name and Fields in the if function becasue the PowerBI will tell us it's a composition key. But we can use order column.

     

    Under Order column, each number represents one measure we have in our table. So for example, I will write as:

     

    = If (Numeator'[Order] = 0, Table'[Count of A], if (Numeator'[Order] = 1, Table'[Count of B],Table'[Count of C])) / If (Denominator'[Order] = 0, Table'[Count of A], if (Denominator'[Order] = 1, Table'[Count of B],Table'[Count of C]))

     

    Hope it helps.

  • We want to help you but your description is too vaugue.

    Please write it again clearly.

    Provide example input data as table text (not a screen print) so we can import the data to build a soution for you.

    Also provide the example desired output, with a clear description of the process flow.

    Take care to use the same table and field names in the input, output and description so we can understand your problem and help you.

    Dont bother posting your DAX code that does not work or suggesting things like "Field parameters". 

    Just describe the input, the outputs and the flow and let us decide the best DAX method. Thanks.

     

    You will get a quick response if you put time and effort into writing clear problem descriptions.

    Vaugue descriptions waste your time and ourtime.

    Look foward to helping you when the above information is forthcoming.