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
tomislav_mi
Helper II
Helper II

Dynamic Agregation - hardest so far

Hey guys,

I am struggling with one of the hardest mind games I have encountered in DAX so far.

I have a data set that can be pivoted to cohort table like this:

 Sum of EndingMRR  YearsActive     
 Row Labels                                 0             1           2             3             4           5
 2020-01                        8,000     7,000     7,000     6,800     7,800   7,500
 2020-02                      16,000   15,000   13,000   12,000   12,000 
 2020-03                        5,000     4,300     4,000     4,000  
 2020-04                        7,000     7,500     7,500   
 2020-05                      14,000   14,100    
 Grand Total                      50,000   47,900   31,500   22,800   19,800   7,500


I would need to divide MRR from each active year with their base from zero year - i.e. I would need to get retention % of all those customers that are active for a certain number of years.

(for example numbers in orange: for 4th year that would be 19,800 divided with only the sum of orange numbers
from zero years that is 24,000 and I would get 82.5%;
for 5th year that would be 7,500 divided by only 8,000 from zero year etc)

I have tried to do it with the following formula

=
DIVIDE (
    SUM ( CustomerData[EndingMRR] ),
    CALCULATE (
        SUM ( CustomerData[EndingMRR] ),
         ( CustomerData[YearsActive] = "0" )
    )
)


but this is wrong because it is taking the sum of all the numbers from zero year instead of only specific ones.

Using excel to show you the logic and the outcome:

 
 

image.png


Please help! Any advice is welcome.

I appreciate your help guys!

Thank you!

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hi, @tomislav_mi , such a cohort table of dataset does please the eye; but troubles DAX. As for me, I always manage datasets to one-dimensional table whenever possible.

So, unpivot the beautiful cohort table into a plain one like this

DS.png

then try these measures

 

 

 

 

SumUp = SUM( CustomerData[EndingMRR] )

% Retention = 
DIVIDE (
    [SumUp],
    CALCULATE ( [SumUp], CustomerData[YeasActive] = "0", VALUES ( CustomerData[RowLabels] ) )
)

 

 

 

retention.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@tomislav_mi , Try

=
DIVIDE (
SUM ( CustomerData[EndingMRR] ),
CALCULATE (
SUM ( CustomerData[EndingMRR] ),
filter(all(CustomerData), CustomerData[YearsActive] = "0" )
)
)

 

or

 

=
DIVIDE (
SUM ( CustomerData[EndingMRR] ),
CALCULATE (
SUM ( CustomerData[EndingMRR] ),
filter(allselected(CustomerData), CustomerData[YearsActive] = "0" )
)
)

CNENFRNL
Community Champion
Community Champion

Hi, @tomislav_mi , such a cohort table of dataset does please the eye; but troubles DAX. As for me, I always manage datasets to one-dimensional table whenever possible.

So, unpivot the beautiful cohort table into a plain one like this

DS.png

then try these measures

 

 

 

 

SumUp = SUM( CustomerData[EndingMRR] )

% Retention = 
DIVIDE (
    [SumUp],
    CALCULATE ( [SumUp], CustomerData[YeasActive] = "0", VALUES ( CustomerData[RowLabels] ) )
)

 

 

 

retention.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL 

Actually already had it in unpivoted format - VALUES was the key function.

It PERFECTLY works!

Thank you friend!

All the best!

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.

Top Solution Authors