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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
AhmedNagy
New Member

Last year values not showing with multi select on Date

Gross Sales Value PY:= var currentbytiweek = SELECTEDVALUE('Dim Date Weekly'[WEEK_NUM]) var currentbeytiyear = SELECTEDVALUE('Dim Date Weekly'[YEAR]) return calculate ([Gross Sales Value], filter (all('Dim Date Weekly'),'Dim Date Weekly'[WEEK_NUM] =currentbytiweek && 'Dim Date Weekly'[YEAR] = currentbeytiyear -1 )). This code will return the lookup value for last year "only one week" based on selected value condition above. my question :: i want to return multiple values for also perivous year for ex : week1+week2+week3 any help please.

talking about total sum if i select multiple weeks

1 ACCEPTED SOLUTION

@v-xicai @amitchandak  i solved it yesterday , it is all about replace"Values" with "selectedvalue" to return mutiple values , and replace = with "in" . 

Gross Sales Value updated =
var currentbytiweek = VALUES('Dim Date Weekly'[WEEK_NUM])
var currentbeytiyear = SELECTEDVALUE('Dim Date Weekly'[YEAR])
return
SUMX(filter (ALL('Dim Date Weekly'),'Dim Date Weekly'[WEEK_NUM] in currentbytiweek && 'Dim Date Weekly'[YEAR] = currentbeytiyear -1 ),[Gross Sales Value])

View solution in original post

8 REPLIES 8
amitchandak
Super User
Super User

@AhmedNagy , if you have date use year behind measure

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd(Table[Date],-1,Year))

 

Or

Sem week day Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd(Table[Date],-364,Day))

 

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 :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

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

@amitchandak  i'm using custom calendre , which means depending on "dateadd" function will not return a good solution , and i depend only on weeks, 

I want to return the sum of weeks from privous year "if i select multiple weeks"

 

@AhmedNagy , Typically use week rank in case week. And Week year is 52 weeks behind

 

 

This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Same Week last year= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-52))

 

But on multi-select this will work for view by week

 

Is same weekday -364 day is fine or there is some other logic

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),Date[Date] -364)

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

@amitchandak  i'm very thanks for your respoonse , let me tell you  that measure is running successfully in single selection and return accurate data , 

my issue is about multi selection : in this case the result does not show "which suppose to be accumalated in weeks pervious year"

Hi @AhmedNagy ,

 

You may create measure like DAX below.

 

Gross Sales Value PY= CALCULATE([Gross Sales Value], FILTER(ALLSELECTED('Dim Date Weekly'),'Dim Date Weekly'[WEEK_NUM] <=MAX('Dim Date Weekly'[WEEK_NUM]) && 'Dim Date Weekly'[YEAR] = MAX('Dim Date Weekly'[YEAR]) -1 ))

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-xicai  thanks fro your response , but it gives wrong answer because it always return <= the selected week num

@v-xicai @amitchandak  i solved it yesterday , it is all about replace"Values" with "selectedvalue" to return mutiple values , and replace = with "in" . 

Gross Sales Value updated =
var currentbytiweek = VALUES('Dim Date Weekly'[WEEK_NUM])
var currentbeytiyear = SELECTEDVALUE('Dim Date Weekly'[YEAR])
return
SUMX(filter (ALL('Dim Date Weekly'),'Dim Date Weekly'[WEEK_NUM] in currentbytiweek && 'Dim Date Weekly'[YEAR] = currentbeytiyear -1 ),[Gross Sales Value])

@AhmedNagy , Thanks for Sharing. 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors