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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
tonny_bwg
Helper I
Helper I

Help - Year Average Calculation

Dears:
 I want to write a dax to calculate the average of 4 Quarters's value for previous Year,on the page , it has a slicer of Yearmonth, for example selecting 202307, I want to show 2022 year average in card. I got blank in the card with below codes. does anyone help me to solve this issue?
thanks 
--Tonny

 
Codes is as below:

test tbl =
//Inventory % of sales_Year  
 VAR _curyear = [CurrentYear]
 VAR _filteredtbl = FILTER(ADDCOLUMNS(
                        DISTINCT(
                          SELECTCOLUMNS(dim_Date,
                                 "Year",[Year],
                                 "YearQuarter", [YearQuarter])),
                                 "Data", [Inventory % of sales_Quarter]),
                        [Year]=_curyear - 1)
 
Return
  // AVERAGEX(_filteredtbl,[Data])
  CALCULATE(COUNTROWS(_filteredtbl),_filteredtbl)

tonny_bwg_0-1691744417977.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@tonny_bwg , if you do not have date, Create a date with help from month and year

example

date = date([Year], [Month no], 1)

 

Join it with date of date table and then try a measure like

 

Last YTD Sales = CALCULATE(Averagex(Values(Date[Qtr Year]), Calculate(SUM(Sales[Sales Amount]))) ,DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

Last year Sales = CALCULATE(Averagex(Values(Date[Qtr Year]), Calculate(SUM(Sales[Sales Amount]))) ,DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 


YTD Sales = CALCULATE(Averagex(Values(Date[Qtr Year]), Calculate(SUM(Sales[Sales Amount]))) ,previousyear('Date'[Date]))

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@tonny_bwg , if you do not have date, Create a date with help from month and year

example

date = date([Year], [Month no], 1)

 

Join it with date of date table and then try a measure like

 

Last YTD Sales = CALCULATE(Averagex(Values(Date[Qtr Year]), Calculate(SUM(Sales[Sales Amount]))) ,DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

 

Last year Sales = CALCULATE(Averagex(Values(Date[Qtr Year]), Calculate(SUM(Sales[Sales Amount]))) ,DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 


YTD Sales = CALCULATE(Averagex(Values(Date[Qtr Year]), Calculate(SUM(Sales[Sales Amount]))) ,previousyear('Date'[Date]))

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.