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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
QlaroOne
New Member

Distinct count based on multiple measures

Hi all,

 

I have an invoice table with following columns:

- Customer

- Date

- Revenue

 

Customers can have multiple invoices per day, so multiple rows per customer and per date.

 

I need a report where I have following measures filtered by date:

- New customers: distinct customers who had a revenue of 0 in the years before selected dates year, but have a revenue of > 0 in selected dates year
(f.e. if selected "15th of november 2018" and customer has been invoiced on 1th of jan 2018 (no credit note) AND he has also invoiced in 2017, but got a credit note for that entire invoice in 2017=> it's a new customer on selected dates year)

- Ex customers= distinct customers who had a revenue of 0 in year of selection and the year before, but had a revenue > 0 in the year-2 before (before 1th of januari of selected dates year -1)
(f.e. we select 15th of november 2018. Customer has revenue 31th of december 2016, but not afterwards > ex customer. If he has revenue on 1th of januari 2017 > should not be an ex customer)

- Recurring customers = distinct customers who have had revenue in the selected dates year or previous year. So at least 1th of januari of previous year we had revenue for this customer or after that.

 

Of course I have a date table and a customer table linked to this invoive table...

 

Can anyone help us with this seemingly simple problem please?

 

Thanks a lot

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@QlaroOne,

Please note that there is no relationship between date table and invoice table. You can create the following measures in the invoice table. For more details, please review attached PBIX file. 

selectedyear = YEAR(MAX('Date'[Date]))
selected = var selectedyearvalue=CALCULATE(SUM(invoice[Revenue]),FILTER(invoice,YEAR(invoice[Date])=[selectedyear])) return IF(ISBLANK(selectedyearvalue),0,selectedyearvalue)
previousyear = var selectedyearvalue=CALCULATE(SUM(invoice[Revenue]),FILTER(invoice,YEAR(invoice[Date])=[selectedyear]-1)) return IF(ISBLANK(selectedyearvalue),0,selectedyearvalue)
year-2 and before = var selectedyearvalue=CALCULATE(SUM(invoice[Revenue]),FILTER(invoice,YEAR(invoice[Date])<=[selectedyear]-2)) return IF(ISBLANK(selectedyearvalue),0,selectedyearvalue)
new = IF(AND([selected]>0,AND([previousyear]=0,[year-2 and before]=0)),1,0) 
existing = IF([year-2 and before]>0&&[selected]=0&&[previousyear]=0,1,0)
recur = IF([selected]>0 &&[previousyear]>0,1,0)
new count = SUMX(VALUES(invoice[Customer]),[new])
existing count = SUMX(VALUES(invoice[Customer]),[existing])
recur count = SUMX(VALUES(invoice[Customer]),[recur])

1.PNG

Regards,
Lydia

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

@QlaroOne,

Please note that there is no relationship between date table and invoice table. You can create the following measures in the invoice table. For more details, please review attached PBIX file. 

selectedyear = YEAR(MAX('Date'[Date]))
selected = var selectedyearvalue=CALCULATE(SUM(invoice[Revenue]),FILTER(invoice,YEAR(invoice[Date])=[selectedyear])) return IF(ISBLANK(selectedyearvalue),0,selectedyearvalue)
previousyear = var selectedyearvalue=CALCULATE(SUM(invoice[Revenue]),FILTER(invoice,YEAR(invoice[Date])=[selectedyear]-1)) return IF(ISBLANK(selectedyearvalue),0,selectedyearvalue)
year-2 and before = var selectedyearvalue=CALCULATE(SUM(invoice[Revenue]),FILTER(invoice,YEAR(invoice[Date])<=[selectedyear]-2)) return IF(ISBLANK(selectedyearvalue),0,selectedyearvalue)
new = IF(AND([selected]>0,AND([previousyear]=0,[year-2 and before]=0)),1,0) 
existing = IF([year-2 and before]>0&&[selected]=0&&[previousyear]=0,1,0)
recur = IF([selected]>0 &&[previousyear]>0,1,0)
new count = SUMX(VALUES(invoice[Customer]),[new])
existing count = SUMX(VALUES(invoice[Customer]),[existing])
recur count = SUMX(VALUES(invoice[Customer]),[recur])

1.PNG

Regards,
Lydia

Hi v-yuezhe-msft

 

Thanks a lot for your response. Is there a way to do it with the relationship between dates en invoice table? Because I need this relationship for other measures/reports...

 

Thanks a lot!

Anonymous
Not applicable

@QlaroOne,

You would need to create another date table and create relationship between the date table invoice table for other measures.

Regards,
Lydia

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.