cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
corvada Member
Member

Comparing 2 calculatetables with each other for calculating numbers of won and lost clients

Hi everyone,

 

I am struggling with some DAX-formulas and hopefully someone of you can help me.

 

I have 2 tables, an invoice-table and a calendar-table. The information of the invoice-table:

 

CustomerInvoiceInvoice_DateYear_InvoiceAmount_Excl_VATYMD-keyQuarterYear-Quarter
110011-3-20142014252014030112014 - Q1
210025-6-20142014402014060522014 - Q2
310039-9-20142014352014090932014 - Q3
4100410-12-20142014122014121042014 - Q4
110051-4-20152015452015040122015 - Q2
210063-3-20152015382015030312015 - Q1
310072-2-20152015272015020212015 - Q1
510084-6-20152015302015060422015 - Q2
610092-8-20152015602015080232015 - Q3
710107-7-20152015402015070732015 - Q3
8101115-10-20152015352015101542015 - Q4
1101221-2-20162016732016022112016 - Q1
210137-11-20162016452016110742016 - Q4
5101415-7-20162016602016071532016 - Q3
610152-4-20162016602016040222016 - Q2
7101628-8-20162016382016082832016 - Q3
9101714-1-20162016102016011412016 - Q1
1010188-11-20162016152016110842016 - Q4
11101925-11-20162016272016112542016 - Q4
110201-4-20172017982017040122017 - Q2
5102123-2-20172017582017022312017 - Q1
710228-12-20172017362017120842017 - Q4
9102324-12-20172017202017122442017 - Q4
1010246-6-20172017122017060622017 - Q2
1110251-6-20172017272017060122017 - Q2
1210268-6-20172017252017060822017 - Q2

 

 

Format of a report:Quarterly Churn comparion.JPG

 

The end result of the dummy data should be:

 

End Results.PNG

 

I want to compare each quarter the information from the last 4 quarters (current) with the information from the prior period.

For example on LTM (Last Twelve Months) Q1-17, I want to compare the periods 2016-Q2 until 2017-Q1 (current) with the period 2016-Q1 until 2016-Q4 (prior period) and than calculate the number of lost clients, steady clients and won clients.

 

For example, I want to calculate the won clients, that are the clients who bought in the current period and not in de prior period. 

 

Won Customers LTM =
VAR CustomerLTM = CALCULATE(DISTINCTCOUNT(Invoices[Customer]);
                                  FILTER(ALL('Calendar');
                                  ** what do I have to put here? 
VAR PriorCustomers = CALCULATE(DISTINCTCOUNT(Invoices[Customer]);
                                     FILTER(ALL('Calendar' );
                                    ** what do I have to put here? 
RETURN
COUNTROWS(
EXCEPT(CustomerLTM; PriorCustomers ) )
))

 

Can someone help me?

 

Thanks in advance,

 

With kind regards,


Cor

 

@Zubair_Muhammad

1 ACCEPTED SOLUTION

Accepted Solutions
corvada Member
Member

Re: Comparing 2 calculatetables with each other for calculating numbers of won and lost clients

I think I’ve found it:

Won Customers LTM = 
VAR CustomerLTM = CALCULATETABLE(VALUES(Invoices[Customer]);
                         DATESBETWEEN ('Calendar'[Date];
                         NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( 'Calendar'[Date] ) ) );
                         LASTDATE ( 'Calendar'[Date] )))
VAR PriorCustomers = CALCULATETABLE(VALUES(Invoices[Customer]);
                       DATESBETWEEN('Calendar'[Date];
                        DATEADD(STARTOFQUARTER('Calendar'[Date]);-4;QUARTER);
                        DATEADD(ENDOFQUARTER('Calendar'[Date]);-1;QUARTER)))              
RETURN
COUNTROWS(
    EXCEPT(CustomerLTM;PriorCustomers))

View solution in original post

3 REPLIES 3
Stachu Super Contributor
Super Contributor

Re: Comparing 2 calculatetables with each other for calculating numbers of won and lost clients

this may help you:
https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/
the pattern used looks like this

    DATESBETWEEN (
        Calendar[FullDate],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( Calendar[FullDate] ) ) ),
        LASTDATE ( Calendar[FullDate] )
    )



Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

corvada Member
Member

Re: Comparing 2 calculatetables with each other for calculating numbers of won and lost clients

@Stachu

Thanks for your reply, the pattern you've mentioned is I think for the current period. What do I have to fill in the formula for the prior period? 

 

Regards,


Cor

 

corvada Member
Member

Re: Comparing 2 calculatetables with each other for calculating numbers of won and lost clients

I think I’ve found it:

Won Customers LTM = 
VAR CustomerLTM = CALCULATETABLE(VALUES(Invoices[Customer]);
                         DATESBETWEEN ('Calendar'[Date];
                         NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE ( 'Calendar'[Date] ) ) );
                         LASTDATE ( 'Calendar'[Date] )))
VAR PriorCustomers = CALCULATETABLE(VALUES(Invoices[Customer]);
                       DATESBETWEEN('Calendar'[Date];
                        DATEADD(STARTOFQUARTER('Calendar'[Date]);-4;QUARTER);
                        DATEADD(ENDOFQUARTER('Calendar'[Date]);-1;QUARTER)))              
RETURN
COUNTROWS(
    EXCEPT(CustomerLTM;PriorCustomers))

View solution in original post

Helpful resources

Announcements
Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 137 members 1,736 guests
Please welcome our newest community members: