Forum Discussion

ShubhamTrivedi's avatar
ShubhamTrivedi
Frequent Visitor
1 year ago
Solved

power bi

Hello Power BI community,

 

I have got a matrix visual in a report. In that, I have created a quick measure called Duration which is the difference between created on date and completed by date. At the very last of the visual, as you know it gives out total of that duration column. I want to change it to Average. Can you please assist me with this ?

 

Thank you

  • You need to use a X iterator function like AVERAGEX

     

    Here is some example test data

     

    ProjectStartEnd
    119/02/202520/02/2025
    215/02/202520/02/2025
    306/02/202516/02/2025
    405/02/202509/02/2025
    529/01/202507/02/2025
    627/01/202505/02/2025
    722/01/202529/01/2025
    812/01/202522/01/2025
    910/01/202519/01/2025

     

    Here are three measures

     

    Duration = 
    DATEDIFF(
        SELECTEDVALUE('yourtable'[Start]),
        SELECTEDVALUE('yourtable'[End]),
        DAY
    )

     

     

     

    Total = 
    SUMX(yourtable,[Duration])

     

     

     

    Average = 
    AVERAGEX(yourtable,[Duration])

     

     

    Here is the output

     

     

    Note how the X function iterates the Duration measure for each row in the table.

    Please click thumbs up and accept solution if it works (it will work). Thanks ğŸ˜€

     

    Learn more here (skip the annoying adverts)

    https://learn.microsoft.com/en-us/dax/averagex-function-dax

    https://www.youtube.com/watch?v=UMxeti9udMo

     

1 Reply

  • You need to use a X iterator function like AVERAGEX

     

    Here is some example test data

     

    ProjectStartEnd
    119/02/202520/02/2025
    215/02/202520/02/2025
    306/02/202516/02/2025
    405/02/202509/02/2025
    529/01/202507/02/2025
    627/01/202505/02/2025
    722/01/202529/01/2025
    812/01/202522/01/2025
    910/01/202519/01/2025

     

    Here are three measures

     

    Duration = 
    DATEDIFF(
        SELECTEDVALUE('yourtable'[Start]),
        SELECTEDVALUE('yourtable'[End]),
        DAY
    )

     

     

     

    Total = 
    SUMX(yourtable,[Duration])

     

     

     

    Average = 
    AVERAGEX(yourtable,[Duration])

     

     

    Here is the output

     

     

    Note how the X function iterates the Duration measure for each row in the table.

    Please click thumbs up and accept solution if it works (it will work). Thanks ğŸ˜€

     

    Learn more here (skip the annoying adverts)

    https://learn.microsoft.com/en-us/dax/averagex-function-dax

    https://www.youtube.com/watch?v=UMxeti9udMo