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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
abhishekdas72
Frequent Visitor

week over week calculation

Hello Power BI Community,

I need to calculate week over week variance from a source table in SQL DB . Please help me out with the below situation

there is a heirarchy which goes like this

Region > Trade > Manager > Supplier > Part

 

regionTrademanagersupplierpartspend
R2T3M3S2P5               1,051,229
R2T3M1S2P7               1,669,068
R2T3M1S4P3               6,473,159
R2T1M2S1P1               3,540,942
R2T3M3S4P1               9,691,689
R2T2M3S3P2               3,726,536
R2T2M1S3P8               9,836,488

 

the heirarchical structure looks like this

abhishekdas72_0-1680848876285.png

 

What happens is each week the actuals are posted in same source table and i need to figure out a way to retain figures for the previous week only so that i can subtract from current week actuals and check which region > trade > manager > supplier >part has shown the high variance. 

variance = current week actuals - previous week actuals 

If suppose a part actuals has not been posted or there is no weekly history it should be added to the list under the same herirachy region > trade > manager > supplier >part.

i have connected to the SQL databse using import query method actuals are posted to the same table from which i am calculating the values .can this be done in power BI or this need something to be done at source level while importing the data or in SQL database( this is not an option as admin only grant generic READ only acess to the DB).  
@DimaMD @amitchandak @olgad @DimaD  Please help

4 REPLIES 4
DimaMD
Solution Sage
Solution Sage

@abhishekdas72 I have created an example, see the attached file and try to implement it in your report.
first measure (example)

1 - 
spend PW = 
 VAR CurrentWeek = SELECTEDVALUE(dates[Weekmun])
 VAR currentYear = SELECTEDVALUE(dates[Year])
 VAR maxWeeknum = CALCULATE( MAX( 'dates'[Weekmun]), ALL( dates))
 return
 SUMX( 
     FILTER( ALL(dates),
     IF( CurrentWeek = 1, 
     'dates'[Weekmun] = maxWeeknum && 'dates'[Year] = currentYear -1,
     'dates'[Weekmun] = CurrentWeek - 1 && 'dates'[Year] = currentYear)),
     [Total spend]
 )


 second measure (example)

Previous week = 
 CALCULATE( [Total spend], 
 FILTER( ALL(dates) , dates[Weekmun] = SELECTEDVALUE(dates[Weekmun]) - 1 && dates[Year] = SELECTEDVALUE(dates[Year])))

 

DimaMD_0-1680865318444.png

 


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
abhishekdas72
Frequent Visitor

Yes they are present

@abhishekdas72 Provide more detailed sample data, or attach a pbix file, without confidential data


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
DimaMD
Solution Sage
Solution Sage

@abhishekdas72 Hi, Are dates present in your fact table?


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors