cancel
Showing results for
Did you mean:
haosmark Helper I

## Calculate daily average, formula is giving bad results

I'm trying to calculate an average, per person, per day, however the formula is returning invalid an result.

Here's the formula that I use:

```_Avg Invoices per Day = CALCULATE(
DIVIDE(
COUNT('Billing Stats'[WO#]),
DISTINCTCOUNT('Billing Stats'[DateInvoiced]),
0
)
)```

and this is the data: In the example above, 195, 114, 84 are the amounts of invoices each person created for an entire month.

195/20 is not 20, 84 / 20 does not equal to 5, etc. I'm thinking that my calculation is off, because the formula takes the billing days count per person, which could differ from one to another. So I basically need to mod my formula to calculate the average based on a total billing days overall, not by how many days someone particular billed for. I hope this makes sense.

I tried to tweak the formula to the one below, but I got an error stating that a table of multiple values was supplied where only one is expected:

```_Avg Invoices per Day = CALCULATE(
DIVIDE(
COUNT('Billing Stats'[WO#]),
CALCULATE(
DISTINCTCOUNT('Billing Stats'[DateInvoiced]),
FILTER('Billing Stats', ALLSELECTED('Billing Stats'[DateInvoiced]))
),
0
)
)```

This is what my data table looks like: 3 REPLIES 3 Super User IV

## Re: Calculate daily average, formula is giving bad results

First, I can't fathom the CALCULATE in your first formula. You can get rid of it. Second, I imagine that your issue is that you want the number of billing dates to remain constant (20) but you have a measure so it is taking context into account for how many billing days there are. This is why your total is correct but not your individual rows. Try something like:

```_Avg Invoices per Day =
DIVIDE(
COUNT('Billing Stats'[WO#]),
CALCULATE(DISTINCTCOUNT('Billing Stats'[DateInvoiced]),ALL('Billing Stats')),
0
)```

This will count all of the billing days each time the measure is calculated, removing any other context.

---------------------------------------

Putting square pegs in round holes since 1972.

##### I have a NEW book! DAX Cookbook from Packt
Over 120 DAX Recipes!

Proud to be a Datanaut!

haosmark Helper I

## Re: Calculate daily average, formula is giving bad results

It's still giving me inaccurate data  Community Support

## Re: Calculate daily average, formula is giving bad results

Hi @haosmark,

I think you have add some additional filter on visual level or page level, right?

If this is a case, please share the sample pbix file to test, it will be help for analysis.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

Announcements #### Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section. #### April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights. Top Solution Authors
Top Kudoed Authors
Users online (2,347)