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
KristianSG
Frequent Visitor

How to get the count of new clients for the last "x" days

Hi guys,

 

I'm pretty new and I've hit a snag trying to get the count of new clients that came in the last "x" days. The measure I created is the following:

 

New Clients = calculate(
count(Client[Name]),
DATESBETWEEN('Calendar'[Date],DATEADD(LASTDATE('Calendar'[Date]),-1*'NewClientsLast "X" Days'[NewClientsLast "X" Days Value],DAY),LASTDATE('Calendar'[Date])))
 
Basically, I have a Client table and a calendar table linked to it. I'm using a "What-if" parameter in order to customize the search a little bit more by allowing the user to see how many clients have been onboarded in the last "X" days (1 to 120 days is the period I set up in the parameter). The DAX measure seems to be correct since PBI is taking it in as valid but I'm getting blank results on my card. Where am I blundering? Thank you in advance!!!
1 ACCEPTED SOLUTION

@KristianSG 

I think this dax may help you,

 

new clients = CALCULATE(DISTINCTCOUNT(Sheet2[client name]),DATESBETWEEN(Sheet1[Date],TODAY()-SELECTEDVALUE(x_days[x_days]),TODAY()))
 
Sheet2[client name] - client name in client table
Sheet1[Date] - date field in calendar table
x_days[x_days] - is your what-if parameter (min 0 to max 120, increment to 1)
 
 

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@KristianSG Maybe: https://community.powerbi.com/t5/Quick-Measures-Gallery/New-and-Returning-Customers/m-p/168297#M13

 

Otherwise, Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hello @Greg_Deckler ,

 

First of all, thank you for your fast reply. I'm sorry that I couldn't get my message across successfully so let me try that again. Below, you can see a screenshot where 2 cards are displayed. The card on the left is showing the correct numbers of clients that have been onboarded since October the 1st until today (as you can see on the right that is possible thanks to the filters). On the right side, you can see the card which is showing me blank results because apparently, sth is wrong with my measure. On top of the 2 cards, you can see a slicer where the user can enter a value between 1 and 120 (translated in days). What I want to achieve is that when the user entered for instance 30 in the slicer, the card showed the clients we onboarded in the last 30 days. If the user entered 60, then the number of clients onboarded in the last 60 days. I'm sorry if this time is unclear too but it's my first post. I have the table in excel but I don't know how could I attach it. Thank you in advance for helping me. 

Captura.JPG

@KristianSG 

I think this dax may help you,

 

new clients = CALCULATE(DISTINCTCOUNT(Sheet2[client name]),DATESBETWEEN(Sheet1[Date],TODAY()-SELECTEDVALUE(x_days[x_days]),TODAY()))
 
Sheet2[client name] - client name in client table
Sheet1[Date] - date field in calendar table
x_days[x_days] - is your what-if parameter (min 0 to max 120, increment to 1)
 
 

@RohiniP-26 Thank you very much, man! The DAX function worked properly. I will mark your comment as a solution. Many thanks!!!

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.