Forum Discussion

deb_power123's avatar
deb_power123
Icon for Helper V rankHelper V
4 years ago
Solved

DAX query to create DAX table with average values per month against category

Hi All,   I have the below input source table with Audit Date,Score,SchoolName and PercentageStudents columns and  table name as Table. I need to find the average of score and percentageStudents pe...
  • wdx223_Daniel's avatar
    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%"
                        )
                    )
        )
    )

     

  • deb_power123's avatar
    deb_power123
    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.

  • deb_power123's avatar
    deb_power123
    4 years ago

    Hi wdx223_Daniel 

     

    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

  • wdx223_Daniel's avatar
    wdx223_Daniel
    4 years ago
    IF (
                        [Category] = "AverageScore",
                        FORMAT (
                            CALCULATE (
                                AVERAGE ( 'Table'[Score] ),
                                FORMAT ( 'Table'[AuditDate], "MMMM - yyyy" ) = _m
                            )*1000,
                            "0.00M"
                        )