Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hello
I am a beginner DAX user and I have a serious problem with calculating the average using variables defining a range of values.
The problem is as follows:
Table: 'public Measurement'
1. average value for the entire range (10 results) as a separate column - works well
AV_N =
CALCULATE (
AVERAGE ( 'public Measurement'[result]);
FILTER (
ALLSELECTED ('public Measurement');
'public Measurement'[characteristicId] = MAX ( 'public Measurement'[characteristicId])
)
)
The result of the measure is as follows
2. average value for 5 results as a separate column - it seems to work well but the value range is entered "manually"
average value from a range using variables (the measure doesn't work, why?)
Instead of constant values defining the average calculation range (1 and 5 ), I need to use variables.
the variable defining the final range of the value must be calculated, for example:
var stop = count('public measurement'[number]) (instead of the value 5)
How to use variables in such a measure?
Please help
Solved! Go to Solution.
welcome back
Thank you for your suggestions, it allowed me to locate the problem.
Instead of count() I used the countx() function and it works very well
thank you again
welcome back
Thank you for your suggestions, it allowed me to locate the problem.
Instead of count() I used the countx() function and it works very well
thank you again
There shouldn't be any difference between COUNT and COUNTX. But your new solution made me understand that the number-Characteristicid combination in the source table is unique.
Also COUNT/COUNTX should work properly only if [number] restarts from 1 for each characteristicid.
note: the 'public Measurement'[number] >= start_av a gument is not needed in all cases.
Hi @Zbig62
as part of the debugging process you can create a measure Test = count('public measurement'[number]) and see if returns what you've expected it to return.
Hello
Thanks for fast reaction.
This is where I have a problem, see the results in the table where the stop_av variable should have the value 10.
As a result, it obtains a bad average value
Please help me, I don't know how to do it
Thank you for clarifying your problem one more time. That was clear to me already. My point was that it doesn't seem that you are aware of what var stop_av = count('public Measurement'[number]) returns. You only have an expectation that it should always return 10 while this is not true. In fact this expression will be evaluated within the filter context of evaluation. It n other words it might return different number for each number-characteristicid combination depending how many times this combination is repeated in the Source data table which I personally don't know for lack of information. But I can say it won't be 10 for all combinations unless all combinations have actually 10 rows. If you want to return the maximum [number] for each [caharastaristid] then you can try
var stop_av = CALCULATE ( MAX ( 'public Measurement'[number] ), FILTER ( ALLSELECTED ( 'public Measurement',
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
23 | |
21 | |
20 | |
13 | |
12 |
User | Count |
---|---|
41 | |
32 | |
23 | |
23 | |
22 |