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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Correct DAX Measure to show result even when the respective field is not selected

Hi,
I have created a DAX Measure calculation to calculate churned clients count for each Month-Year when a client has not made any sales after 30 days from their last transaction date till date (current month-year).

Lapsed Clients Count =
VAR LastTransactionDate = CALCULATE(MAX('Transaction'[Transaction Date Key]),ALL('Transaction Date'))
VAR ClientsNoSales = CALCULATETABLE(VALUES(Client[Instance Name]),
FILTER(ALL('Transaction Date'),
'Transaction Date'[Date] >= LastTransactionDate &&
'Transaction Date'[Date] < MIN( 'Transaction Date'[Date]) -30 ))
RETURN
COUNTROWS(ClientsNoSales)

Result:
SaloniGupta_0-1624811595995.png


Now if I remove the Instance Name(Client Name) from the above table, everything goes blank.

SaloniGupta_1-1624811989373.png

Can you pls help me correct the DAX so that even if I don't select Client Name, it shows me the Lapsed Clients Count with respect to Month-Year as shown below?

SaloniGupta_2-1624812258554.png

 

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

13 REPLIES 13
Anonymous
Not applicable

Hi,

I get an Access Denied message.  Also, please clarify what you mean by "made any sales after 30 days from their last transaction date till date (current month-year)".  Please illustrate with a simple example.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur,
Here is a simple example of my requirement,
I just need the count of Clients for each month-year after their last transaction date (forget about the last 30 days).
So, the below example in the screenshot is for 1 Client, where its last transaction of 655.0 was done in the month of March - 2019 and after that, there were no transactions/sales and I am trying to take the count for each month after their Last Sales date till current month (which works fine with my logic).
Now, when I remove the filter on Client, I want to display the counts of all clients who did not make any sales after their last transaction date.

SaloniGupta_1-1624986571728.png

 

The result should display something like this:

SaloniGupta_2-1624987162193.png

Please, let me know if you need more information and you should be able to access the report template now.
This is the logic that I am currently working with:

Test Count logic =
CALCULATE(COUNTX(VALUES('Client'[Instance Name]),[Instance Name]),
FILTER(ALL('Transaction Date'),
'Transaction Date'[Date] >= [Latest Sales Date]
&& 'Transaction Date'[Date] < MIN('Transaction Date'[Date])
))
and the logic for the Latest Sales date is :
Latest Sales Date = CALCULATE(LASTDATE('Transaction'[Transaction Date Key]),ALL('Transaction Date') ).

The problem with my logic is with the Latest Sales Date which is correct for each client but when I don't select Client, it gives me the Latest Sales Date as 6/29/2021 (today's date) which is not right and my count logic goes off.
SaloniGupta_1-1624997758715.png

 

Please let me know your thoughts on this?

Hi,

I do not see any data in your file

Untitled.png

I suggest you share your tables in an MS Excel file and show the expected result there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi,

You may download my PBI file from here.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur 
Thank you for your reply, I have looked into the logic but I believe it is not giving correct results.
here is the sample output:
1) say for Client Id = 35323, Date of last interaction = 12/3/2020 and so the Churned Customers logic should show 1 for dates after Dec-2020, but it shows for all the dates (from Jan-2017 till Dec-21)

SaloniGupta_0-1626118547024.png

 

Here is another example,
2) for Client Id = 541, Date of last interaction = 10/7/2019 and so the Churned Customers logic should mark 1 from November 2019.

SaloniGupta_1-1626118547022.png

 

and a similar thing happening with the Client Id = 30025, Date of Last interaction = 10/3/2020, but churned customers logic shows 1 from Jan-2020 rather than Nov-2020.
If you could please help me resolve these errors or provide an alternative approach?

Anonymous
Not applicable

Hi @Ashish_Mathur,

The below DAX gives me correct Last Transaction Date for each Client Id
Last Transaction Table = SUMMARIZE (
'Transaction','Client'[Client Id],
"Last Transaction Date", LASTDATE('Transaction'[Transaction Date Key]),
"DaysSince", DATEDIFF(LASTDATE('Transaction'[Transaction Date Key]),TODAY(),DAY))

Now, can you help use this and calculate the count of churned customers after their Last Transaction Date?
I was trying the below dax calculation but it gives me the error "multiple values were supplied":
CALCULATE(COUNTX(VALUES('Client'[Instance Name]),[Instance Name]),
FILTER(SUMMARIZE('Transaction', Client[Client Id],"DaysSince", DATEDIFF(LASTDATE('Transaction'[Transaction Date Key]),TODAY(),DAY)),
DATESBETWEEN('Transaction Date'[Date],MINX(ALL('Transaction Date'),'Transaction Date'[Date]-[DaysSince]),MAX('Transaction Date'[Date]))
))

Can you please help me in building the logic with this?

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @Ashish_Mathur,
This logic works perfectly. Thank you so much for your effort.
One last ask, can we build the Churned Clients logic only up to the end of the previous month. Since there is a possibility that the client may have a transaction in the current month and we do not already want to mark it as churned until the completion of the current month?

You are welcome.  Modify the measure to:

Churned Customers = COUNTROWS(FILTER(SUMMARIZE(CALCULATETABLE(VALUES(Clients[Client key]),DATESBETWEEN('Calendar'[Date],MINX(ALL('Calendar'),'Calendar'[Date]),MIN('Calendar'[Date])-1)),Clients[Client key],"ABCD",[Revenue],"EFGH",[Date of last interaction]),[ABCD]=blank()&&[EFGH]<min('Calendar'[Date])&&[EFGH]<>BLANK()))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@Anonymous it will be much easier if you can provide the sample pbix file. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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