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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Calculate Average Expense

Hello,

 

I've been trying for the past hour, alongside searching on here, to calculate average daily spend by category and failing miserably... I wondered if anyone could provide advice.  In summary, I have:

Column A = Names

Column B = Type of Expense (say 'Flights', 'Petrol' et cetera)

Column C = Expense Quantity

Calculated value = Number of days charged

 

I have already got measures for total spend (e.g. total flight spend by person), but I am now trying to calculate the average for each type of expense by the name; for example in Excel I could do...:

=IF(AND(ColumnA="John Smith",ColumnB="Petrol"),ColumnB/Calculated Value,"Error")

 

I would be looking to replicate this for each type of expense; note that the calculated value for days charged is obviously going to be the same for the specific name.  As an example:

NameType of ExpenseCalculated Value (Days Charged)Total Expenses for Type of ExpenseAverage
John SmithFlight510060
John SmithFlight520060
John SmithPetrol55010
Joe BloggsFlight2050025

 

Thanks for any help that you can provide!

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Anonymous,

I think you may need to write a variable in your formula with summarize function to add custom filed apply the first aggregate calculation, then you can use iterator function on these values to apply second aggregate mode.

For example:

Measure =
VAR summary =
    SUMMARIZE (
        ALLSELECTED ( Table ),
        [Name],
        [Type of Expense],
        "Total", [TotalExpense]
    )
RETURN
    AVERAGEX ( summary, [Total] )

You can take a look at the following blog about measure calculation on the total level:

Measure Totals, The Final Word 

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Anonymous,

I think you may need to write a variable in your formula with summarize function to add custom filed apply the first aggregate calculation, then you can use iterator function on these values to apply second aggregate mode.

For example:

Measure =
VAR summary =
    SUMMARIZE (
        ALLSELECTED ( Table ),
        [Name],
        [Type of Expense],
        "Total", [TotalExpense]
    )
RETURN
    AVERAGEX ( summary, [Total] )

You can take a look at the following blog about measure calculation on the total level:

Measure Totals, The Final Word 

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@Anonymous , columns not seem correct to me

But you can have measure like this

=IF(AND(table[Name]="John Smith",Table[Type of Expense]="Petrol"),divide(count(Table[Type of Expense])/sum(Table[ Calculated Value (Days Charged)])),blank())

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.