Forum Discussion
Problem with visuals displaying the first N values and a dynamic "other" group
- Anonymous1 year ago
Hi, noviceBI
Thank you very much for your prompt response. I am glad that you are interested in my DAX, which reflects your humble and eager-to-learn attitude.
1.Firstly, regarding the meaning of SELECTEDVALUE. The SELECTEDVALUE function is used to return the value in the current context. If no value is selected, it returns a default value. You can understand it as returning the current row value in a measure. You can replace it with aggregation functions like MAX() or MIN(), and the result will only differ in the total section. This is related to the context dependency of measures.
For the difference between calculated columns and measures, you can refer to the following link:
Solved: What is the difference between a measure and calcu... - Microsoft Fabric Community
2.Secondly, adding the filter 'Incidents 2024'[Processus] IN VALUES('Processus avec autres'[Processus]) is mainly to aggregate the 'Processus avec autres'[Processus] field in our newly created calculated table. If you remove this filter condition, it will return the aggregated value of the 'Incidents 2024'[Processus] IN Processus1 field, which means it will return a fixed value for each row value of the 'Processus avec autres'[Processus] field. As shown in the figure below:
If you add this filter condition, it forms an AND condition. 'Incidents 2024'[Processus] IN Processus1 is to ensure that the returned value is in the TOPN and to aggregate each row value of the 'Processus avec autres'[Processus] field separately. For better understanding, you can also replace the filter 'Incidents 2024'[Processus] IN VALUES('Processus avec autres'[Processus]) with 'Incidents 2024'[Processus] = MAX('Processus avec autres'[Processus]), which is closely related to your first question. Our solution's overall idea is to return the aggregated result that meets the requirements based on the context of the 'Processus avec autres'[Processus] field. Theoretically, its return value should be the content of all 'Processus avec autres'[Processus], but the visualization automatically does not display empty values during aggregation.
3.Finally, regarding your third question, this is also related to the first question. As I mentioned earlier, the total section will be different. You can understand the total section as the output result of a card visual object without the context of the 'Processus avec autres'[Processus] field. Since the output result of SELECTEDVALUE is empty, and empty is not equal to the text "Autres", the output result is false.
The false result is CALCULATE( COUNT('Incidents 2024'[Incident]), 'Incidents 2024'[Processus] IN Processus1, 'Incidents 2024'[Processus] IN VALUES('Processus avec autres'[Processus]) ). You might wonder why it should not return empty here, but the return result includes the total value of all TOPN parts. This is why the VALUES() function is used. If you use 'Incidents 2024'[Processus] = MAX('Processus avec autres'[Processus]), the return result is empty, while VALUES() returns the entire column value in the total section.
For more details, please refer to:
VALUES function (DAX) - DAX | Microsoft Learn
If you need the total value to include all results, you can modify the measure as follows:
Measure = VAR Processus1 = SUMMARIZE( TOPN( [Parameter Value], SUMMARIZE(ALLSELECTED('Incidents 2024'), [Processus], "count", COUNT('Incidents 2024'[Incident])), [count], DESC ), [Processus] ) RETURN IF(ISINSCOPE('Processus avec autres'[Processus]), IF( MAX('Processus avec autres'[Processus]) = "Autres", CALCULATE( COUNT('Incidents 2024'[Incident]), NOT('Incidents 2024'[Processus] IN Processus1) ), CALCULATE( COUNT('Incidents 2024'[Incident]), 'Incidents 2024'[Processus] IN Processus1, 'Incidents 2024'[Processus] IN VALUES('Processus avec autres'[Processus]) ) ),COUNT('Incidents 2024'[Incident]))Here is the final result:
I hope my answer helps you understand. Of course, this is just my understanding of the practical application of the function.
For a more official explanation, you can refer to the following link:
DAX overview - DAX | Microsoft Learn
I believe you will become an even more outstanding user than us.Please find the attached pbix relevant to the case.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi noviceBI ,
Your problem is that you are trying to do the rank on the Incidents, and since there is no context related to the date when yoiu do that filter it will overwrite the context and you get the incorrect result for this you need to do your context for the rank based on the aggregation of values and also of the months so that you can get the correct calculation.
Check this post that has an explanation for when you have several columns:
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
- noviceBI1 year agoHelper I
Hi MFelix !
I will consult this article to try to understand, thank you!
But how do you explain the last table with an incorrect ranking and number of incidents, knowing that here I have not filtered by date?
- MFelix1 year agoSuper User
The questions is that you are calculating the Total incidents for all the table and the result for you measure is always 230 meaning that all of them are on the same rank number.
WIthout any further knowledge of your model it's difficult to pin point the problem but I believe that your Total Incidents measure may be part of the problem.
- noviceBI1 year agoHelper I
Hello MFelix,
Yes I suspect that in the absence of details on the model used, it is difficult to understand where the problem comes from.
Here is the link to the pbix file in question, hoping that it helps to find the solution:
https://drive.google.com/file/d/1twjK2NH4O0za03n_1FdqgwPZZsn5PnaA/view?usp=drive_link
Thanks again for your help.