Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello;
as a relative newbie to power bi and DAX, i tried to create my own dataset to practice dax syntax, but then i am confused how to solved this;
i tried to find out how to solved this, but i can't find the related issue, would you please to show me the right dax syntax to solved this;
any guidance on achieving this will be much appreciated
warm regards;
vick
Solved! Go to Solution.
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
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi @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
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsDear 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
Dear Felix;
thank you very much for your response, i tried to follow step by step the guidance you gave to me, but i still found mistaken value when create measure for TotalAverageQty; did i write wrong syntax, or i missed some thing here;
here is my result
Do you want to get the following table regarding the product average?
If this is the case, you can use the following DAX get this it
AverageProduct = GROUPBY('Dateset_Table','Dateset_Table'[GroupProduct],"AverageQty",AVERAGEX(CURRENTGROUP(),'Dateset_Table'[Qty]))
When creating the vis_table in Power BI, remeber to change the value AverageQty to Average.
Hi Jessica;
thank you very much for your reply, i tried to follow your guidance but different result i got, did i missed some thing here?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
97 | |
84 | |
67 | |
60 |
User | Count |
---|---|
150 | |
120 | |
99 | |
87 | |
68 |