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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Dividing by Dimension with filters

Hello, I have the database below and I need to know the Avg of total sales per salesman and sum the avgs in the total line.

 

The measure below is the measure with the filters I need to be kept

#Invoice = 

CALCULATE(
             DISTINCTCOUNT('table1'[invoiceno]),
             'table1'[ItemStatus] = "Paid" ||
             'table1'[ItemStatus] = "Unpaid" ||
             'table1'[ItemStatus] = BLANK() )
 

Then I need to calculate the Avg Total Sales for each Salesman based on the  [#Invoice] calculation above (distinct count of invoices with filters)

 

I tried to divide the #Invoice by the avg sales but it didn't work because in the  [ #Invoice ] I have filters.

 

How do I get the Average of total sales based on the calculation #Invoice?

 

Then I will need to aggregate these values by salesman

 

SalesmanInvoiceNoInvoiceStatusTotalSales
Kieran Kearns52750Paid59.09
Kieran Kearns190492Paid62.94
Kieran Kearns150310Unpaid62.94
Kieran Kearns125692Paid62.94
Kieran Kearns131323Paid62.94
Kieran Kearns180406 62.94
Kieran Kearns152700Waiting62.94
Kieran Kearns144922Overdue62.94
Kieran Kearns143436Overdue62.94
Kieran Kearns142426Overdue62.94
Kieran Kearns136590Paid62.94
Kieran Kearns176288Paid62.94
Kieran Kearns113310Paid62.94
Kieran Kearns100702Overdue62.94
Kieran Kearns148045Overdue62.94
Kieran Kearns145719Unpaid62.94
David Logan145724Paid62.94
David Logan137286Paid62.94
David Logan137170Paid62.94
David Logan200306Unpaid62.94
David Logan195156Unpaid62.94
David Logan188609Unpaid62.94
David Logan99696 62.94

 

Desired results

 

For Kieran Kearns 

[#Invoice] = 10 invoices 

[Total Sales] = 625.55

[Avg Sales p salesman] = 62.55 (625.55 / 10)

 

For David Logan 

[#Invoice] = 7 invoices 

[Total Sales] = 440.58

[Avg Sales p salesman] = 62.94 (440.58 / 7)

 

Then the total I need the sum of the averages of all salesman instead avg.

 

Any way I can achieve this? In the real dataset I will have to do this for a huge set of salesman

 

Thanks!

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , check the measures

 

#Invoice =
CALCULATE(
DISTINCTCOUNT('table1'[invoiceno]),
Filter('table1', 'table1'[ItemStatus] in( "Paid", "Unpaid") || isblank('table1'[ItemStatus]) ))


#Avg Invoice =
divide(sum('table1'[TotalSales]),
CALCULATE(
DISTINCTCOUNT('table1'[invoiceno]),
Filter('table1', 'table1'[ItemStatus] in( "Paid", "Unpaid") || isblank('table1'[ItemStatus]) )))

#Avg Invoice by sales man = calculate([#Avg Invoice], filter(allselected('table1'), 'table1'[Salesman] = max('table1'[Salesman] )))

View solution in original post

2 REPLIES 2
HarishKM
Impactful Individual
Impactful Individual

@Anonymous  Hey 
I have created 3 measures
Total sales = sum (sales[totalsales])
# of invoices = countrows(sales)
avg sales = AVERAGE(Sales[TotalSales])
go to filter or slicer and select Paid ,unpaid,Blank to fulfill your requirement.
Left side matrix is filtered by slicer and right side matrix is hard coded filter .

 

HarishKM_0-1617944823675.png

 

 

amitchandak
Super User
Super User

@Anonymous , check the measures

 

#Invoice =
CALCULATE(
DISTINCTCOUNT('table1'[invoiceno]),
Filter('table1', 'table1'[ItemStatus] in( "Paid", "Unpaid") || isblank('table1'[ItemStatus]) ))


#Avg Invoice =
divide(sum('table1'[TotalSales]),
CALCULATE(
DISTINCTCOUNT('table1'[invoiceno]),
Filter('table1', 'table1'[ItemStatus] in( "Paid", "Unpaid") || isblank('table1'[ItemStatus]) )))

#Avg Invoice by sales man = calculate([#Avg Invoice], filter(allselected('table1'), 'table1'[Salesman] = max('table1'[Salesman] )))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.