Forum Discussion
How to average value with group by and summarized
- 8 years ago
Hi vicks,
The calculation of measures in dax is based on context so if you make any calculation based on the columns you select to give context to your information it will give you the result you need.
In this case and since you want the average you only need to create a simple measure of average:
Average qty = AVERAGE('Dataset'[Qty])As you can see below the values gives for the average are as you need. However this result can also be achieve choosing the Average when adding the column Qty to your visuals without the need for any calculations.
If you want to have a more complex formula using the division you should use the following formula:
Avr Divide = DIVIDE(SUM('Dataset'[Qty]);COUNT('Dataset'[GroupProduct]) )As you can see because the formulas are based on context it knows that you are grouping the information so no need to put it on your formula.
However as you can see the result based on context doesn't give you the correct amount on total line so you need to add additional context to your last row redo your measure to:
Average qty Total = IF ( HASONEFILTER ( 'Dataset'[GroupProduct] ); [Average qty]; SUMX ( ALL ( 'Dataset'[GroupProduct] ); [Average qty] ) )Regards,
MFelix
Hi vicks,
The calculation of measures in dax is based on context so if you make any calculation based on the columns you select to give context to your information it will give you the result you need.
In this case and since you want the average you only need to create a simple measure of average:
Average qty = AVERAGE('Dataset'[Qty])
As you can see below the values gives for the average are as you need. However this result can also be achieve choosing the Average when adding the column Qty to your visuals without the need for any calculations.
If you want to have a more complex formula using the division you should use the following formula:
Avr Divide = DIVIDE(SUM('Dataset'[Qty]);COUNT('Dataset'[GroupProduct]) )As you can see because the formulas are based on context it knows that you are grouping the information so no need to put it on your formula.
However as you can see the result based on context doesn't give you the correct amount on total line so you need to add additional context to your last row redo your measure to:
Average qty Total =
IF (
HASONEFILTER ( 'Dataset'[GroupProduct] );
[Average qty];
SUMX ( ALL ( 'Dataset'[GroupProduct] ); [Average qty] )
)
Regards,
MFelix
Dear Felix;
After redo step by step i found the "litlle" missing thing, i just typo the dax syntax;
that should be
AvqQtyTotal = IF(HASONEFILTER('MyDataset'[GroupProduct]),[AvqQty],SUMX(ALL('MyDataset'[GroupProduct]),[AvqQty]))
what i wrote
AvqQtyTotal = IF(HASONEFILTER('MyDataset'[GroupProduct]),[AvqQty],SUMX(ALL(MyDataset'[GroupProduct]),[AvqQty]))
now the result as i expected ;
Thank you very much for your help, i can closed this issue, and that would be belong to your suggestion;
warm regards;
vick