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
huynhphuc242
Frequent Visitor

total by year and ranking based on specific year

Hi everyone, 

 

I need help with a DAX for a calculated column for "total per year" and "Tier based on 2018 revenue" like below: 

 

customerbilled dateYear billedrevenueTotal per yearTier based on 2018 revenue
A1/1/20182018$300$1,8001
A2/1/20182018$300$1,8001
A3/1/20182018$300$1,8001
A4/1/20182018$300$1,8001
A5/1/20182018$300$1,8001
A6/1/20182018$300$1,8001
A1/1/20192019$1,000$6,0001
A2/1/20192019$1,000$6,0001
A3/1/20192019$1,000$6,0001
A4/1/20192019$1,000$6,0001
A5/1/20192019$1,000$6,0001
A6/1/20192019$1,000$6,0001
B1/1/20182018$5,000$11,0003
B2/1/20182018$6,000$11,0003
B12/1/20192019$70,000$150,0003
B12/1/20192019$80,000$150,0003

 

I need this total per year to rank customers into Tier based on their revenue in the year of 2018. So the Tier column has this logic: 

 

Tier2018 revenue logic
1<2,000
2<4,000
3<15,000
4<200,000

 

So even though customer B has 150,000 revenue in 2019 (tier 4), their Tier in 2018 is 3 so they will still be in Tier 3. 

 

Much appreciated all your help! 

1 ACCEPTED SOLUTION
v-gizhi-msft
Community Support
Community Support

Hi,

 

According to your description, i have two ways to meet your requirement:

By Calculated Column:

1)Create a column regardless of year:

Column = SWITCH(true,[Total per year]<2000,1,[Total per year]>2000&&[Total per year]<4000,2,[Total per year]>4000&&[Total per year]<15000,3,[Total per year]>15000,4)

 2)Create a column to filter year:

rank-column = IF('Table'[Column]<>CALCULATE(MIN('Table'[Column]),ALLEXCEPT('Table','Table'[customer])),CALCULATE(MIN('Table'[Column]),ALLEXCEPT('Table','Table'[customer])),'Table'[Column])

And it shows:

41.PNG

 

By Measure:

1)Create a measure to change the revenue to the same group by customer:

Measure = CALCULATE(SUM('Table'[revenue]),FILTER(ALLSELECTED('Table'),'Table'[customer] in FILTERS('Table'[customer]) && YEAR('Table'[billed date]) = 2018))

2)Create a measure to rank the measure above:

rank-measure = IF([Measure]<2000,1,IF([Measure]<4000,2,IF([Measure]<15000,3,IF([Measure]<200000,4))))

And it shows:

42.PNG

 

Here is my test pbix file.

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

View solution in original post

6 REPLIES 6
v-gizhi-msft
Community Support
Community Support

Hi,

 

According to your description, i have two ways to meet your requirement:

By Calculated Column:

1)Create a column regardless of year:

Column = SWITCH(true,[Total per year]<2000,1,[Total per year]>2000&&[Total per year]<4000,2,[Total per year]>4000&&[Total per year]<15000,3,[Total per year]>15000,4)

 2)Create a column to filter year:

rank-column = IF('Table'[Column]<>CALCULATE(MIN('Table'[Column]),ALLEXCEPT('Table','Table'[customer])),CALCULATE(MIN('Table'[Column]),ALLEXCEPT('Table','Table'[customer])),'Table'[Column])

And it shows:

41.PNG

 

By Measure:

1)Create a measure to change the revenue to the same group by customer:

Measure = CALCULATE(SUM('Table'[revenue]),FILTER(ALLSELECTED('Table'),'Table'[customer] in FILTERS('Table'[customer]) && YEAR('Table'[billed date]) = 2018))

2)Create a measure to rank the measure above:

rank-measure = IF([Measure]<2000,1,IF([Measure]<4000,2,IF([Measure]<15000,3,IF([Measure]<200000,4))))

And it shows:

42.PNG

 

Here is my test pbix file.

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

thank you for your help @v-gizhi-msft 

amitchandak
Super User
Super User

Try the following as columns

Total 2018 year =sumx(filter(table,table[customer]=earlier[table[customer] && table[Year billed] =2018),	table[revenue])

Tier = if(table[Total 2018 year] <20000," <2,000",....)

 

If first is showing 2018 against all rows, then you can use it if or case to develop tier.

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Hi @amitchandak , thank you for your advice, I tried create a calculated column as you suggest but got this error saying too few arguments were passed to the sumx fuction.

 

I tried this: Total 2018 year = sumx(filter(table,table[customer]=EARLIER(table[customer] && table[year_billed]=2018), table[revenue]))
Ashish_Mathur
Super User
Super User

Hi,

Why do you want to solve this with a calculated column formula?  Why not solve it with a measure?


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

Hi @Ashish_Mathur , I want to calculate the total 2018 as a calculated column so the Tier can be based off this column. With measure, it does not work as I add more filter breakdown to the table. My goal is to see the revenue retention from customers in cohort 2018. 

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.