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
henryvu93
Helper I
Helper I

Problem with Calculated Column

Hi guys,

 

I have a table with the sample like this: 

 

DateCustomer
1/1/2015A
1/1/2015B
1/1/2015C
1/1/2015D
1/1/2015E
1/1/2015F
1/1/2015G
1/1/2015H
2/1/2015A
2/1/2015B
2/1/2015D
2/1/2015E
2/1/2015F
2/1/2015C
2/1/2015I
2/1/2015J
2/1/2015K
2/1/2015L
2/1/2015M
2/1/2015N
3/1/2015A
3/1/2015B
3/1/2015C
3/1/2015E
3/1/2015D
3/1/2015F
3/1/2015G
3/1/2015H
3/1/2015I
3/1/2015J
4/1/2015A
4/1/2015B
4/1/2015C
4/1/2015D
4/1/2015E
4/1/2015F

 

I wanted to create a calculated column with this formula:

 

"Prev12Members = CALCULATE(DISTINCTCOUNT(Table[Customer]), SAMEPERIODLASTYEAR(Table[Date]))" 

However, it does not result in any values. It worked when I tried creating a measure and created a table (Visualization) with Date & this measure. Just wonder if it is possible to create calculated column as mentioned? Any insight will be greatly appreciated! Thanks!

 

 Regards,

Henry

 

 

1 ACCEPTED SOLUTION

Hi,

 

Try this formula

 

=CALCULATE( AVERAGEX(VALUES(Customer[Date]), [Churn Rate]), DATESBETWEEN ( Customer[Date], EDATE(MIN(Customer[Date]),-11),MAX(Customer[Date])))

 

Hope this helps.


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

View solution in original post

13 REPLIES 13
Ashish_Mathur
Super User
Super User

Hi,

 

That will not work as a calculated column - it will only work as a measure.  But if the measure is already working for you, why do you want to write that as a calculated column?


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

Hi @Ashish_Mathur,

 

Thanks for your reply. Actually after this step, I want to summarize the table into a new table with date & the measure. However, with the measure "Prev12Members", my table did not show anything. I am thinking if I can create a column and summarize the table based on that column it might be possible.

 

Regards,

Henry

Hi,

 

Please describeyour entire question and show the expected result.


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

Hi @Ashish_Mathur,

 

Basically, with the source table, I want to have 2 measures in a particular month: "prev12Members" (customers in the last 12 months) & "MembersRetained" (customers who were there in the last 12 months & are still customers now). Then, I create a measure for customer churn rate, which depends on those 2. Finally, I want to create another measure, which is the moving (or rolling) 12-month average churn rate:

 

Moving_Average_ChurnRate_12_Months = 

CALCULATE(
    AVERAGEX(Table, (power(2- [MembersRetained]/[Prev12Members],1/12)-1)),
        DATESBETWEEN (
        Table[Date],
        NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE (Table[Date] ) ) ),
        LASTDATE (Table[Date] )
    ) 
)

 For the Table Visualization, I managed to get the churn rate, but when I tried to calculate the moving 12-month average churn rate, the formula did not work. Thank you very much!

 

Regards,

Henry

Hi,

 

Try this

 

=CALCULATE( AVERAGEX(Table, (power(2- [MembersRetained]/[Prev12Members],1/12)-1)), DATESBETWEEN ( Table[Date], EDATE(MIN(Table[Date]),-11),MAX(Table[Date])))

 

I am assuming that Table is a calendar table.  there should be a relatioship from the the Date column of your base data to your Calendar table (Table).  In the slicer/Filter, select a certain month (which should be a column in your Calendar table)


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

Hi @Ashish_Mathur,

 

Thanks for your reply! I tried your formula and apparently it is still not working (the moving 12-month average churn rate is not "moving") . Maybe it's better if I give you the formula I used for calculating the "MembersRetained" measure:

 

 

MembersRetained = 

VAR membersInPrevious12Month = CALCULATETABLE(Table, SAMEPERIODLASTYEAR(Table[Date])) 

return 

CALCULATE(DISTINCTCOUNT(Table[Customer]), FILTER(Table,CONTAINS(membersInPrevious12Month, Table[Customer],Table[Customer])))

I think the problem lies in the fact that our filter to get the 12-month range does not get into [MembersRetained] & [Prev12Members] at all. Thank you very much!

 

Regards,

Henry

Hi,

 

Share the link from where i can download your file.  Please let me know exactly the numbers that you are expecting so that i can compare my answer with yours.


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

Hi @Ashish_Mathur,

 

I'm afraid I can't share with you the file as it's kind of confidential. However, you can take a look at the screenshot attached below:

 

AVG.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

As you can see, I just want the average of the last 12 months churn rate, which is the meaning of the "moving 12 months average churn rate" (for e.g. Dec 2017 measure will be average of churn rates from Jan 2017 to Dec 2017). The formula did not work so it showed blanks all over for the measure. Thanks!

 

Regards,

Henry

Hi,

 

I will need some data to work with.  Share a dummy dataset with Churn rate already computed there.


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

Hi @Ashish_Mathur.

 

Thanks. Please find the link below for your reference.

 

https://drive.google.com/open?id=14ba6G8fCo6E98m3Jh-6aOA7P7b6qL-eG

 

Regards,

Henry

Hi,

 

Try this formula

 

=CALCULATE( AVERAGEX(VALUES(Customer[Date]), [Churn Rate]), DATESBETWEEN ( Customer[Date], EDATE(MIN(Customer[Date]),-11),MAX(Customer[Date])))

 

Hope this helps.


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

Hi @Ashish_Mathur,

 

The formula worked perfectly! Thanks a lot for your help!

 

Regards,

Henry

You are welcome.


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

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.