Forum Discussion
DAX query to create DAX table with average values per month against category
- 4 years ago
NewTable=GENERATE(
NewTable = GENERATE ( SUMMARIZE ( SELECTCOLUMNS ( 'Table', "CurrentMonth", FORMAT ( 'Table'[AuditDate], "MMMM - yyyy" ) ), [CurrentMonth] ), ADDCOLUMNS ( DATATABLE ( "Category", STRING, { { "AverageScore" }, { "AveragePercentage" } } ), "ParamScore", VAR _m = [CurrentMonth] RETURN IF ( [Category] = "AverageScore", FORMAT ( CALCULATE ( AVERAGE ( 'Table'[Score] ), FORMAT ( 'Table'[AuditDate], "MMMM - yyyy" ) = _m ), "" ), FORMAT ( CALCULATE ( AVERAGE ( 'Table'[PercentageStudents] ), FORMAT ( 'Table'[AuditDate], "MMMM - yyyy" ) = _m ), "0%" ) ) ) ) - 4 years ago
Hi wdx223_Daniel This is exactly I was looking for , thankyou for letting me know the approach.I treid to implement is and it worked.Thanks a ton.
- 4 years ago
Here the Score column in input table is in unit of Billion but I want to convert and show the value in Million and put M as a suffix. so 1billion = 1000 million
In ParamScore column, I want to display 0.1875 and 0.75 to 187.5 M and 750 M respectively.
Is it possible and if so please suggest the changes in the above formula?
We require to show the below :-
1. We need to convert from billion to million
2. Add M suffix in the above loop formula
Kind regards
Sameer
- 4 years ago
IF ( [Category] = "AverageScore", FORMAT ( CALCULATE ( AVERAGE ( 'Table'[Score] ), FORMAT ( 'Table'[AuditDate], "MMMM - yyyy" ) = _m )*1000, "0.00M" )
Hi,
Smpa01's solution should suffice, but if you insist on calculated table you can use the following DAX:
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
Hi ValtteriN I am unable to replicate your calculation, is it possible for you to share the .pbix file as shared by smpa01?
Also the calculation you performed looks perfect , but is it feasible to add a measure column as below which schould categorize the averagescore and average pecentage? It needs to be placed inside column entries and not as the column header as shown in the above solution of smpa01.
It is fine if we can just place these static values in the table in anyways like we do in data table but not sure if this is supported in calculated table ?
:-
| Month | Value | Measures |
| August | 0.1875 | Average_score |
| September | 0.75 | Average_score |
| August | 39.90% | Average_percentage |
| September | 36.10% | Average_percentage |
I truly appreciate for all your help . It should be contained in the columns because I will require to show these values in my visualization and we cant show the value if it is contained in a column header.
Kind regards
Sameer
- ValtteriN4 years ago
Community Champion
Hi,
deb_power123
I am unable to share the file but here is a more detailed explanation. Maybe this helps:
Source data:
Go to table tools and select new table:For the DAX explanation:
The DAX is separated into two different calculated tables which are appended together using UNION. The basic idea is to use SUMMARIZE to group value by month (hence this:AverageX_Score[AuditDate].[Month]). Then we perfrom the aggregate calculation we want (AVERAGE in this case:AVERAGE(AverageX_Score[Score]))