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
85dhruv
Frequent Visitor

Tricky measure : Sum at Total not matching the sum of individual row

HI ,

 

I need help with writing a measure where the results are different for row level and total level in a table visualization.

The target is to show the sum of sales for the first 3 years.

 

Opportunity IDYearSales
1201910
1202020
1202130
1202240
2201850
2201960
2202070
2202180

 

Needed Result :

IdFirst 3 Year sum 
160sum of 2019,2020,2021
2180sum of 2018,2019,2020
Total240 

 

But my measure does the calculation of this measure at total level and hence sums up 2018,2019 and 2020 since these are the first 3 years. 

 

Meausre :

 

Sales (3yrs) =

var year_start = min('Table'[Year])
Return
calculate(sumx(
FILTER('Table'; 'Table'[Year] <= (year_start + 2) ) ;
'Table'[Sales] )
)
 

Can you please help me correct this ?
 
Feedback on formatting welcome too 😛

 

thanks

 

1 REPLY 1
Anonymous
Not applicable

@85dhruv Please try this measure. In case you want to include more columns in your final table please add those columns in summarize function.

Measure = 
VAR _sales = CALCULATE(SUM('Table'[Sales]),TOPN(3,'Table','Table'[Year],ASC))
VAR _table = SUMMARIZE('Table','Table'[Opportunity ID],"_totalsales",_sales)
RETURN IF(HASONEVALUE('Table'[Opportunity ID]),_sales,SUMX(_table,[_totalsales]))

 

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