Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Arjun_reddy
Helper I
Helper I

dax query

Hi Community team,

 

need you help on one of my requirement:
can you please write a dax measure on the below formula 
formula=((max year of total occasions on highest retail channel)-(same period last year of total occasions on retail channel))/(same period last year of total occasions on retail channel)
note: which is havin highest retail channel on max year for the same retail channel should reflect for pevious year 

categoryyearsales Row Labelsbulbschairssofatables 
chairs20215000 2021400013800550012000 
tables20216000 20228000800092003400 
bulbs20226000       
sofa20224500  sofa is the highest value in max year the value is: 9200 and the same category sofa get the value on previous year sales    
chairs20228000       
chairs20216000 growth rate:67%    
chairs20212800 sample formula=( (max year of highest top1 category on sales)-(previous year of same category on sales))/(previous year of same category on sales) 
sofa20224700       
bulbs20222000       
sofa20215500       
tables20216000       
tables20223400       
bulbs20214000       

Thanks,

Arjun Reddy. L

1 ACCEPTED SOLUTION

maybe try to convert year column from TEXT to number





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
Arjun_reddy
Helper I
Helper I

Hi ryan,

 

I am getting the value format error can you please correct the below query, and where i can add the power bi file into this post, can you please help me.

Arjun_reddy_0-1692087168733.png

growthrate_on_occ =
VAR  _year=max('Tostitos_MP'[YEAR])
VAR _t=TOPN(1,SUMMARIZE(FILTER('Tostitos_MP','Tostitos_MP'[YEAR]=_year),'Tostitos_MP'[RETAIL CHANNEL],"sale",sum('Tostitos_MP'[TOTAL OCCASIONS])),[sale] )
var _C= maxx(_t,[RETAIL CHANNEL])
VAR _cy=sumx(FILTER('Tostitos_MP','Tostitos_MP'[YEAR]=_year&&'Tostitos_MP'[RETAIL CHANNEL]=_C),'Tostitos_MP'[TOTAL OCCASIONS])
VAR _py=sumx(FILTER('Tostitos_MP','Tostitos_MP'[YEAR]=(_year-1)&&'Tostitos_MP'[RETAIL CHANNEL]=_C),'Tostitos_MP'[TOTAL OCCASIONS])
return _cy
 
Thanks, 
Arjun Reddy

maybe try to convert year column from TEXT to number





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




after changed the year format as value, the dax query working fine and getting the accurate value,

Thanks a lot team, your helping is really awesome 

 

Arjun Reddy.

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Ashish_Mathur
Super User
Super User

Hi,

What if more than 1 category has the highest sale in the farthest year. say sofa and bulbs?  How should the growth rate be calculated then?


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

@Arjun_reddy 

is this what you want?

Measure = 
VAR  _year=max('Table'[year])
VAR _t=TOPN(1,SUMMARIZE(FILTER('Table','Table'[year]=_year),'Table'[category],"sale",sum('Table'[sales])),[sale])
var _C= maxx(_t,[category])
VAR _cy=sumx(FILTER('Table','Table'[year]=_year&&'Table'[category]=_C),'Table'[sales])
VAR _py=sumx(FILTER('Table','Table'[year]=(_year-1)&&'Table'[category]=_C),'Table'[sales])
return _cy/_py-1

11.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.