Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Trying to sum amounts by company for the last 3 days that they had any amount. So if a company had amounts yesterday, 4 days ago, and 7 days ago I would want to only sum those amounts. Creating a date rank almost solved this but since its ranking every day regardless of company, the lookback function below in my measure is missing data.
This is what the overall table looks like with all companies.
Company | Amount | Date | date Rank | |||
A | $ 10 | 5/17/2021 | 91 | |||
B | $ 16 | 5/16/2021 | 90 | |||
C | $ 11 | 5/15/2021 | 89 | |||
C | $ 13 | 5/14/2021 | 88 | |||
A | $ 15 | 5/12/201 | 87 | |||
D | $ 9 | 5/12/2021 | 87 | |||
D | $ 9 | 5/10/2021 | 86 | |||
A | $ 8 | 5/10/2021 | 86 | |||
A | $ 12 | 5/1/2021 | 85 |
date rank = RANKX('Table1','Table 1'[Date],,ASC,Dense)
Company | Amount | Date | date Rank | |||
A | $ 10 | 5/17/2021 | 91 | |||
A | $ 15 | 5/12/2021 | 87 | |||
A | $ 12 | 5/1/2021 | 85 |
Solved! Go to Solution.
@Anonymous , Try with these changes
//column
date rank = RANKX(filter('Table1', [Company] =earlier([Company])),'Table 1'[Date],,ASC,Dense)
//measure
Last 3 Days of Amount =
var _max = MAXX(filter(allselected('Table 1'),[Company] =max([Company])), 'Table 1'[date rank])
return
CALCULATE(SUM('Table 1'[Total Amount]),'Table 1',ALL('Table 1'),'Table 1'[date rank]>=_max-3)
Hi, @Anonymous
I tried to create a sample pbix file based on the explanation. I added some more random data for the company B and C to check.
Please check the below picture and the sample pbix file's link down below.
Hi, My name is Jihwan Kim.
If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.
Linkedin: linkedin.com/in/jihwankim1975/
Twitter: twitter.com/Jihwan_JHKIM
@Anonymous , Try with these changes
//column
date rank = RANKX(filter('Table1', [Company] =earlier([Company])),'Table 1'[Date],,ASC,Dense)
//measure
Last 3 Days of Amount =
var _max = MAXX(filter(allselected('Table 1'),[Company] =max([Company])), 'Table 1'[date rank])
return
CALCULATE(SUM('Table 1'[Total Amount]),'Table 1',ALL('Table 1'),'Table 1'[date rank]>=_max-3)