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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Community Champion
Community Champion

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!
Thank you for the kudos 🙂

Anonymous
Not applicable

@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

 

Anonymous
Not applicable

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))

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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