Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello experts,
Need few clarifications regarding DAX functions:
1. MAX vs SELECTEDVALUE -- which is better to use?
2. Is it better to compare DateKey(20250531) format or date format in measures? (a < DateKey or a < fullDate.. which will be faster??)
3. Shall I create a separate measure with SELECTEDVALUE or MAX and then refer it in all the dependent measures? Or use the function in variable for every measure?
I know, on a single measure, It won't affect much. But, when the same change is done in 40-50 measures, I believe it can impact the performance
Hi @PowerBIDAXProb,
Thank you for reaching out to the Microsoft Fabric Community, and thanks to @FBergamaschi, @bhanu_gautam, for their valuable inputs on this thread.
Both functions serve different purposes. SELECTEDVALUE is ideal when you expect only a single value in the filter context (such as a slicer), as it returns that value or blank/default otherwise. MAX, on the other hand, is more robust when multiple values may exist—it returns the highest value in context and avoids blanks. So, the better option depends on the use case, but from a reliability standpoint, MAX is generally safer when the context isn’t guaranteed to be single valued. SELECTEDVALUE function - DAX | Microsoft Learn
Use SELECTEDVALUE instead of VALUES in DAX - DAX | Microsoft Learn
Using DateKey (an integer) for comparisons is typically more efficient than using full date formats, especially in large models, as numeric comparisons are faster and lighter on the engine. However, full date formats are necessary when working with DAX time intelligence functions like DATESYTD or SAMEPERIODLASTYEAR. A good practice is to maintain both columns in your Date table use DateKey for joins and filters and use full dates for calendar logic. MAX function (DAX) - DAX | Microsoft Learn
If the same logic (like SELECTEDVALUE(Date[Month])) is used across many measures, creating a reusable base measure improves maintainability and consistency. However, for performance-critical scenarios or when the value is used only within a specific measure, defining it as a VAR within the measure can be more efficient. Since you're working with 40–50 measures, reusing shared expressions where applicable is helpful but always validate with Performance Analyzer or DAX Studio if performance is a concern.
If you have any questions regarding this, please feel free to reach out to us. We will be happy to help you. If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.
Thank you for using Microsoft Community Forum.
1. There in no optimal choice as they are different. MAX returns the maximum value among many values visibile in the filter context, SELECTEDVALUE returns either the only value visibile in the filter cotext or blank (or a chosen default value you can set when there are multiple values visibile)
2. Date is better if DateKey(20250531) is a text otherwise if it is a number DateKey(20250531) is better as numbers are always fastwer to manage for keys. Avoid please datetime unless really needed
3. Surely better separate measures and their reuse
MAX vs SELECTEDVALUE: The choice between MAX and SELECTEDVALUE depends on the context of your data and what you are trying to achieve. MAX returns the maximum value in a column, which is useful when you need the highest value. SELECTEDVALUE returns the value when there is only one value in the context, otherwise it returns a specified alternate result (or BLANK if not specified). SELECTEDVALUE is often used in scenarios where you expect a single value in the context and want to handle cases where there might be multiple values more gracefully. If you are certain that there will always be a single value in the context, SELECTEDVALUE can be more intuitive and safer to use.
Comparing DateKey vs fullDate: Comparing a numeric DateKey (e.g., 20250531) is generally faster than comparing full date formats because numeric comparisons are less computationally intensive than date comparisons. However, the performance difference might be negligible unless you are performing a very large number of comparisons. Using DateKey can also simplify the logic and improve readability if your data model is designed around these keys.
Creating a separate measure vs using the function in a variable: Creating a separate measure with SELECTEDVALUE or MAX and then referring to it in all dependent measures can improve performance and maintainability. This approach avoids redundant calculations and makes your DAX code cleaner and easier to manage. Using variables within each measure can also be beneficial for performance, as it ensures that the calculation is performed only once per evaluation context. However, if the same logic is used across multiple measures, defining a separate measure is generally the better approach.
Proud to be a Super User! |
|
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
11 | |
10 | |
10 | |
10 |
User | Count |
---|---|
18 | |
13 | |
12 | |
11 | |
8 |