The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hello.
If I have a parameter and I want the max of whichever measure is chosen by the user, how do I create the max? So, if I have three measures in a parameter, e.g. Sales, Profit, and Transactions, I want the maximum of whichever measure from the parameter the user chose. If the user chose Sales, I want max sales. But if theuser chose profit, I want the max profit.
Could you please share the sample PBIX file? Since the sample PBIX or data has not been provided, we will close this thread. If the issue persists, feel free to open a new thread.
Thank you.
Hi @lauriemclolo,
Could you let me know if the issue has been resolved? If not, please share the sample PBIX file so we can assist you in resolving the problem.
Thank you.
You can solve this by combining your field parameter with a SWITCH statement so that the calculation adapts to the user’s choice. Here’s a working DAX pattern:
Max_SelectedMeasure =
VAR SelectedMeasure =
SELECTEDVALUE ( 'Measure Parameter'[Name] ) -- the field parameter
RETURN
SWITCH (
SelectedMeasure,
"Sales", CALCULATE ( MAX ( Sales[SalesAmount] ) ),
"Profit", CALCULATE ( MAX ( Sales[ProfitAmount] ) ),
"Transactions", CALCULATE ( MAX ( Sales[TransactionCount] ) )
)
'Measure Parameter'[Name] comes from the field parameter table Power BI generates when you create a parameter. SELECTEDVALUE tells us which measure the user picked.
The SWITCH evaluates that choice and runs the corresponding expression.
For each case, CALCULATE ( MAX ( … ) ) returns the maximum value of the chosen measure.
If the user picks “Sales,” the formula gives the max sales, if “Profit,” the max profit, and so on.
This way, the measure dynamically responds to the parameter selection and always shows the maximum for whichever metric is chosen.
Hi @lauriemclolo,
As the issue remains unresolved, could you provide a small sample Pbix file along with the expected output? This will help us address the problem more effectively.
Thank you.
Hi @lauriemclolo,
Have you had a chance to review the solution we shared by @Jihwan_Kim @danextian @Shahid12523 @KNP ? If the issue persists, feel free to reply so we can help further.
Thank you.
Hi, I am not sure if I understood your question correctly, but one of ways is to create field parameter and calculation group.
I tried to create a sample pbix file like below, and please check the below picture and the attached pbix file.
You will need to create a measure that references either the field or order column of the parameter - not name column as this will result to an error.
SWITCH (
SELECTEDVALUE ( 'parameter'[parameter order] ),
1, MAX ( 'Table'[sales] ),
2, MAX ( 'Table'[profit] )
)
Note: MAX may not be the actual function to use as this will depend on wha max you are trying to calcualate - eg the max of monthly sales.
Use a SWITCH with SELECTEDVALUE:
If they’re columns:
Selected Measure Max =
SWITCH(
SELECTEDVALUE('Measure Parameter'[Measure Parameter]),
"Sales", MAX('Table'[Sales]),
"Profit", MAX('Table'[Profit]),
"Transactions", MAX('Table'[Transactions])
)
If they’re measures:
Selected Measure Max =
SWITCH(
SELECTEDVALUE('Measure Parameter'[Measure Parameter]),
"Sales", [Max Sales],
"Profit", [Max Profit],
"Transactions", [Max Transactions]
)
👉 Replace [Max Sales], [Max Profit], etc. with your existing max-calculation measures.
They are neither columns nor pre-calculated max measures. It is a parameter of measures, none of which is a max measure. Sales is a Measure, Profit is a Measure and Transactions is a Measure. So, will I have to precaulate the max of each measure?
Hi @lauriemclolo,
Are you talking about field parameters?
Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
User | Count |
---|---|
65 | |
62 | |
60 | |
53 | |
28 |
User | Count |
---|---|
181 | |
82 | |
67 | |
47 | |
44 |