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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Calculate quantity based on average price and region

I'm trying to calculate fuel prices based on data from a separate table. I have two sources for fuel, Table 1 gives me detail of every transaction including Fuel Type, Pump Price, Litres, Transaction Date and Region where the sale took place. In Table 2 I get invoices that only include Fuel Type, Invoice $ Total, Region and Transaction Date. I'm trying to calculate the litres sold in Table 2 based on the average price in the region for the month, and if there are no sales that month, use the overall average.

 

I've created measures that give me the correct averages using the data from Table 1. I think I can get the correct answer by grouping and creating a new table from Table 1, but is it possible to do this using measures? 

 

RegionOctNovDecJanFebAverage
Region 12.262.352.222.08 2.23
Region 22.212.312.172.022.062.15
Region 32.242.332.212.142.102.20
Region 42.262.322.212.16 2.24

 

 

Level 1Invoice AmountDatePrice to useDesired Result
Region 1$1,390.3208/12/20222.22626.3
Region 2$251.6408/12/20222.17116.0
Region 3$239.5008/12/20222.21108.4
Region 4$1,110.0528/11/20222.32478.5
Region 1$515.8528/11/20222.35219.5
Region 1$261.1102/02/20222.23117.1
Region 2$1,044.8302/02/20222.06507.2
Region 3$109.2502/02/20222.1052.0
Region 4$1,259.0002/02/20222.24562.1
2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , You need to unpivot the month in power bi, post that you will have a month

as you do not have a year

Try a date column like this in DAX

 

Date  =

var _date = datevalue("01-"&[Month] & "- " &Year(Today()) )

return

Date(if(month([Date]) <= month(Today()) , year(_date) , year(_date) -1) , month(_date) , 1)

 

You can use this to create a new column in table two

maxx(filter(Table1, Table1[region] = Table2[Region] && eomonth(Table1[Date],0) = eomonth(Table2[Date],0) ), Table1[Rate])

 

refer 4 ways (related, relatedtable, lookupvalue, sumx/minx/maxx with filter) to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

 

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
Anonymous
Not applicable

The HTML tables didn't look right to me, so I'm reposting as images:

tmonkeye_0-1677751701566.png

 

tmonkeye_1-1677751735334.png

 

 

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