Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
Hi Community!
I'm aiming to calculate last week's sales for each product.
My primary sales table has four column:
Date
Product ID
Date
Quantity Sold
I have tried the following formula, but it's yielding an aggregate result that does not disaggregate by product.
Solved! Go to Solution.
Try
Prev Week =
var _year =MAX ( 'Calendar','Calendar'[year] )
var _date = date(_year-1,12,31)
var _maxPweek = weekno(_date)
VAR _maxWeek1 = MAXX('Calendar', 'Calendar'[week_num] )
VAR _maxWeek = if([_maxWeek1]=1 ,_maxPweek, _maxWeek1-1
var _cYear = MAXX ( 'Calendar','Calendar'[year] )
Var _maxYear = if([_maxWeek1]=1,_cYear-1,_cYear)
return
CALCULATE (
SUM ( Sales[amount] ),
FILTER ( all('Calendar'),'Calendar'[year] = _maxYear && 'Calendar'[week_num] = _maxWeek),
)
This Week =
VAR _maxWeek = MAXX('Calendar', 'Calendar'[week_num] )
var _maxYear = MAXX ( 'Calendar','Calendar'[year] )
return
CALCULATE (
SUM ( Sales[amount] ),
FILTER ( all('Calendar'),'Calendar'[year] = _maxYear && 'Calendar'[week_num] = _maxWeek),
)
Hello Community,
I would like to ask for help regarding my concern. I am trying to get the total of each product type through measure and comparing it from last week sold and this week sold but I can only get the total sold of all products when I am filtering my product type. Is there a way to get the total on each product type? Please see below my measures.
Sold Last Week = CALCULATE(SUM('Product Database'[Total Sold]),FILTER(ALL('Product Database'),'Product Database'[Week Rank]=MAX('Product Database'[Week Rank])-1))
Sold This Week = CALCULATE(SUM('Product Database'[Total Sold]),FILTER(ALL('Product Database'),'Product Database'[Week Rank]=MAX('Product Database'[Week Rank])))
Sold Weekly by % = ([Sold This Week]-[Sold Last Week])/'Product Database'[Sold Last Week]
Thank you for your help on this matter.
Create a rank on the week start/end date of week no (YYYYWW) and then use that. Date is my Calendar table here
Week Start date = DATEADD('Date'[Date],-1*WEEKDAY('Date'[Date])+1,DAY)
Week End date = DATEADD('Date'[Date],7-1*WEEKDAY('Date'[Date]),DAY)
Week Num = if('Date'[Week Number] <10 ,'Date'[Year]*10 & 'Date'[Week Number], FORMAT('Date'[Date],"YYYYWW") )
Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)
Measure = CALCULATE([AH], all('Date'),filter('Date','Date'[Week Rank]=max('Date'[Week Rank])-1))
this Week using rank = CALCULATE(sum(Sales[Amount]),all('Date'),filter('Date','Date'[Week Rank]=max('Date'[Week Rank])))
Last Week using rank = CALCULATE(sum(Sales[Amount]),all('Date'),filter('Date','Date'[Week Rank]=max('Date'[Week Rank])-1))
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges
Connect on Linkedin
Hi! Thank you for the response, but I'm looking for a simpler solution. Right now, the following formula works but only with one of the conditions (currYear or currWeek), not both. Do you know what I may be doing wrong here?
Try
Prev Week =
var _year =MAX ( 'Calendar','Calendar'[year] )
var _date = date(_year-1,12,31)
var _maxPweek = weekno(_date)
VAR _maxWeek1 = MAXX('Calendar', 'Calendar'[week_num] )
VAR _maxWeek = if([_maxWeek1]=1 ,_maxPweek, _maxWeek1-1
var _cYear = MAXX ( 'Calendar','Calendar'[year] )
Var _maxYear = if([_maxWeek1]=1,_cYear-1,_cYear)
return
CALCULATE (
SUM ( Sales[amount] ),
FILTER ( all('Calendar'),'Calendar'[year] = _maxYear && 'Calendar'[week_num] = _maxWeek),
)
This Week =
VAR _maxWeek = MAXX('Calendar', 'Calendar'[week_num] )
var _maxYear = MAXX ( 'Calendar','Calendar'[year] )
return
CALCULATE (
SUM ( Sales[amount] ),
FILTER ( all('Calendar'),'Calendar'[year] = _maxYear && 'Calendar'[week_num] = _maxWeek),
)
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
115 | |
113 | |
105 | |
95 | |
58 |
User | Count |
---|---|
174 | |
147 | |
136 | |
102 | |
82 |