Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ronin995
New Member

How to Calculate Average Volume a User spend in a Month

Hello Power Bi Community,

I would like your help to solve how I can visualize in a Bar chart the Avarage volume of money a User spends in a month.
What I tried to use is the following measure: 


AVG Volume per User by Month =
VAR money_ = CALCULATE(
        SUMX(Sales, Sales[products] * (Sales[price]/100)),
        FILTER(
        ALL('Sales'),
        ISONORAFTER('Sales'[created_at], MAX('Calendar'[Date]), DESC) && Sales[status] = "SOLD"
    )
)
VAR AVG_per_User= CALCULATE(
     DIVIDE(money_,[Total Users]),
    FILTER(
        ALLSELECTED('Sales'[created_at]),
        ISONORAFTER('Sales'[created_at], MAX('Calendar'[Date]), DESC)
    )  
)
return AVG_per_User

This is what I get when I put the month and the Year from the calendar table on the X-axis with the Measure in the Y-axis. 
518cfb8c-f8d4-463a-b745-33694f39c48c.png
What I need is the avarage of each month separately. Which doesn't count the one from the previous month. How can I adjust it to make it work as I intend?
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @ronin995 ,

In your formula, you use the ISONORAFTER function, which will include all dates less than the current date in the chart. Modify the formula to:

AVG Volume per User by Month =
VAR money_ =
    CALCULATE (
        SUMX ( Sales, Sales[products] * ( Sales[price] / 100 ) ),
        FILTER (
            ALL ( 'Sales' ),
            EOMONTH ( 'Sales'[created_at], 0 ) = EOMONTH ( MAX ( 'Calendar'[Date] ), 0 )
                && Sales[status] = "SOLD"
        )
    )
VAR AVG_per_User =
    CALCULATE (
        DIVIDE ( money_, [Total Users] ),
        FILTER (
            ALLSELECTED ( 'Sales'[created_at] ),
            EOMONTH ( 'Sales'[created_at], 0 ) = EOMONTH ( MAX ( 'Calendar'[Date] ), 0 )
        )
    )
RETURN
    AVG_per_User

Get the correct result in my sample, I attach my sample below for your reference.

vkalyjmsft_0-1658893472175.png

Reference: EOMONTH function (DAX) - DAX | Microsoft Docs

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @ronin995 ,

In your formula, you use the ISONORAFTER function, which will include all dates less than the current date in the chart. Modify the formula to:

AVG Volume per User by Month =
VAR money_ =
    CALCULATE (
        SUMX ( Sales, Sales[products] * ( Sales[price] / 100 ) ),
        FILTER (
            ALL ( 'Sales' ),
            EOMONTH ( 'Sales'[created_at], 0 ) = EOMONTH ( MAX ( 'Calendar'[Date] ), 0 )
                && Sales[status] = "SOLD"
        )
    )
VAR AVG_per_User =
    CALCULATE (
        DIVIDE ( money_, [Total Users] ),
        FILTER (
            ALLSELECTED ( 'Sales'[created_at] ),
            EOMONTH ( 'Sales'[created_at], 0 ) = EOMONTH ( MAX ( 'Calendar'[Date] ), 0 )
        )
    )
RETURN
    AVG_per_User

Get the correct result in my sample, I attach my sample below for your reference.

vkalyjmsft_0-1658893472175.png

Reference: EOMONTH function (DAX) - DAX | Microsoft Docs

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yanjiang-msft I tried it out and it works as you explained with the example, it was a great learning! Thank you very much!

@v-yanjiang-msft thanks, i'll try out the solution you gave me right away and let you know!

amitchandak
Super User
Super User

@ronin995 , Based on what I got, Try a measure like

 

Cumm = CALCULATE(averageX(values('Date'[Month Year]),calculate(SUM(Sales[Sales Amount]))) ,filter(allselected('Date'),'Date'[date] <=max('Date'[date])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak, unfortunately when I tried to do as you suggested. I get nothing in the chart as it doesn't select any of the data

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.