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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
ChumaAmako
Helper I
Helper I

Distinct Count Based on Filter Expressions

Dear Community,

 

I have a model with an Accounts, Orders, Order Details, Product Details and Calendar table, with all relationships in place. Please download anonymous pbix file HERE.

 

I have a challenge creating measures which computes the following from the Order Table:

 

  1. The number of Passive Consumers; This count of the unique consumers who have not purchased in the past 28 days, but has purchased in the last 35 days and has at least 1 previous order.
  2. The number of Active Consumers; This count of the unique consumers who have not purchased in the past 28 days. For this, I tried this formula; 
     
    No of Active Users = CALCULATE(DISTINCTCOUNT('Order Table'[User Email]),FILTER('Order Table',DATESBETWEEN('Calendar'[Date],MAX('Order Table'[Order Start Date])-28,MAX('Order Table'[Order Start Date]))))
     
    But I get an error when displaying the number in a visual (see pbix file)
     
    Any help will be really appreciated.
     
2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@ChumaAmako - I would try this way:

No of Active Users =
  VAR __MaxDate = MAXX(ALL('Order Table'),[Order Start Date])
  VAR __MinDate = __MaxDate - 28
  VAR __Table = FILTER(ALL('Order Table'),[Order Start Date]>=__MinDate)
RETURN
  COUNTROWS(DISTINCT(SELECTCOLUMNS(__Table,"Email",[User Email])))

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-kelly-msft
Community Support
Community Support

Hi @ChumaAmako

 

Create 2 measures as below:

_Count active = CALCULATE(COUNT('Accounts Table'[Email Address]),FILTER(ALL('Accounts Table'),'Accounts Table'[Email Address]=MAX('Accounts Table'[Email Address])&&'Accounts Table'[Days Since Last Purchase]<=28))
_No of Active Users = 

CALCULATE(DISTINCTCOUNT('Accounts Table'[Email Address]),FILTER('Accounts Table','Accounts Table'[_Count active]>=1)
)

And you will see:

Annotation 2020-08-31 175509.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

View solution in original post

4 REPLIES 4
v-kelly-msft
Community Support
Community Support

Hi @ChumaAmako

 

Create 2 measures as below:

_Count active = CALCULATE(COUNT('Accounts Table'[Email Address]),FILTER(ALL('Accounts Table'),'Accounts Table'[Email Address]=MAX('Accounts Table'[Email Address])&&'Accounts Table'[Days Since Last Purchase]<=28))
_No of Active Users = 

CALCULATE(DISTINCTCOUNT('Accounts Table'[Email Address]),FILTER('Accounts Table','Accounts Table'[_Count active]>=1)
)

And you will see:

Annotation 2020-08-31 175509.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

Greg_Deckler
Community Champion
Community Champion

@ChumaAmako - I would try this way:

No of Active Users =
  VAR __MaxDate = MAXX(ALL('Order Table'),[Order Start Date])
  VAR __MinDate = __MaxDate - 28
  VAR __Table = FILTER(ALL('Order Table'),[Order Start Date]>=__MinDate)
RETURN
  COUNTROWS(DISTINCT(SELECTCOLUMNS(__Table,"Email",[User Email])))

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler  thanks a lot for the solution.

 

Any idea on how I can approach the second measure

 

The number of Passive Consumers; This count of the unique consumers who have not purchased in the past 28 days, but has purchased in the last 35 days and has at least 1 previous order.

@ChumaAmako - Here is a variation on the theme for the passive uers.

No of Passive Users =
  VAR __MaxDate = MAXX(ALL('Order Table'),[Order Start Date])
  VAR __MinDate = __MaxDate - 28
  VAR __MinDate2 = __MaxDate - 35
  VAR __Table1 = SELECTCOLUMNS(FILTER(ALL('Order Table'),[Order Start Date]<__MinDate1),"Email",[User Email]) // users who have bought > 35 days ago.
  VAR __Table2 = SELECTCOLUMNS(FILTER(ALL('Order Table'),[Order Start Date]>=__MinDate1 && [Order Start Date]<__MinDate),"Email",[User Email]) //users bought between 28-35 days agao
  VAR __Table3 = SELECTCOLUMNS(FILTER(ALL('Order Table'),[Order Start Date]>=__MinDate && [Order Start Date]<=__MaxDate),"Email",[User Email]) // users bought in last 28 days
  VAR __Table = INTERSECT(EXCEPT(__Table2,Table3),__Table1)
RETURN
  COUNTROWS(DISTINCT(SELECTCOLUMNS(__Table,"Email",[User Email])))

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.