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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

[Urgent help request] Monthly weighted average price this year vs last year

Hi Power BI experts,

 

I am calculating the inflation impact based on this calculation logic.

 (Monthly weighted average price in this year's month - Monthly weighted average price in previous year's month) * Quantity in this year's month *(-1)

 The basic logic (Pattern A) is done as per the below, but I realized that there are exceptions since we don't have transactions every single month, such as patterns B and C.

 

Could someone help me with building dynamic DAX logic with this sample data? Big thank you in advance!

 Sample data and detailed explanation:

https://docs.google.com/spreadsheets/d/1CIhuSIddVvPKPDFy7m3E98AE4pSeU9WE/edit?usp=share_link&ouid=10...

 

 This year's monthLast year's monthAction
Pattern AYesYesInclude
Pattern BNoYesExclude
Pattern CYesNoExcule if there is no transaction all the way to 24 months ago.

 

Inflation impact =
var cy = SELECTEDVALUE('Calendar Table'[Year])
var cm = SELECTEDVALUE('Calendar Table'[Month Number])

var ly = cy - 1
var cy_items = filter('Data', and(YEAR([Received Date]) = cy, month([Received Date])=cm) )
var ly_items = filter(ALLSELECTED('Data'),  and(YEAR([Received Date]) = ly, month([Received Date])=cm) )

var price_ly = SUMX(ly_items, [Order Unit Price]*[Received Quantity])/sumx(ly_items, [Received Quantity])
var price_cy = SUMX(cy_items, [Order Unit Price]*[Received Quantity])/sumx(cy_items, [Received Quantity])
var qty_cy = sumx(cy_items, [Received Quantity])

return (price_cy - price_ly) * qty_cy * -1

0 REPLIES 0

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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