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 Thankyou
The calculation looks perfect , but is it feasible to add a measure column as below which schould categorize the averagescore and average pecentage? Both these values are measures since you have used the Average function to calculate them in the .pbix file.
It is fine if we can just place these static values in the table in anyways like we do in data table. Please suggest if this can be achieved in the file below you shared.I am really curious if there is any possible approach since its very close to what I was looking for.
| Month | Value | Measures |
| August | 0.1875 | Average_score |
| September | 0.75 | Average_score |
| August | 39.90% | Average_percentage |
| September | 36.10% | Average_percentage |
In your solution , Averagepct and AverageScore are column headers but I want them to appear under column entry as shown above or in any other possible way but 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.
I truly appreciate for all your help .
Kind regards
Sameer