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
AleFVG
Helper I
Helper I

how to create a column with multiple criteria

Hello to everyone!

have create a Query with 5 columns, the column names are "Item", "Desc","Month", "Qty" and "Avg price unit". The structure is like this:

 

ItemDescMonthQtyAvg price unit
L1111AA143
L2222BB166
L3333CC268
L4444DD3103
L1111AA4102,5
L2222BB346
L8888XX240,5
L2222BB434
L2222BB474
L5555EE1110

 

What I would like to do is to add another column into this query, The sixth column is named "Avg unit price last month". I would like to have this column to always display the avg price only only of the most recent month available.

 

Like this:

 

ItemDescMonthQtyAvg price unitAvg unit last month
L1111AA1432,5
L2222BB16615
L3333CC2688
L4444DD31033
L1111AA4102,52,5
L2222BB341515
L8888XX240,50,5
L2222BB431515
L2222BB471515
L5555EE111010

 

Thanks in advance.

 

 

3 REPLIES 3
AleFVG
Helper I
Helper I

Hello!

First of all, thanks for your support!

I try to give a better explanation.

Have a create the following table. This table only contains data for the current year (2020)

 

Screenshot_1.png

 

  • Item fieldIn this field there is an article code that can be repeated several times during the year (currently there are about 13.000 different codes)
  • Total Value
  • Quantity
  • Month
  • AVG Price unit: i added column calculated with dax= Total Value / quantity
  • AVG Price unit last month: this is the column I want to add. I would like that, if a code was purchased in the last month, in this column where that code is present, the avg price unit referring to the last month is inserted. If a code has not been purchased in the last month, avg unit of all the rows where the code is present must be entered

Check Example in the table:

In this case the last month on the table is 5 (May), The only item that has the price in month 5 (May) is the Item L11 and the avg price unit is 1,80$. Therefore, in all the rows where the L11 code is present in the AVG PRICE LAST MONTH column the price will be entered is 1,80$.

For the items L22 and L33 no purchase was made in month 5 (May) then in the column AVG PRICE LAST MONTH the average price (sum total value for Item L22 / sum quantity for item L22) must be entered in all the lines where the codes are present. In the table for L22 the avg price is 3,13$ (sum total value for Item L22 / sum quantity for item L22) and the same for the item L33 the avg is 3,49$.

 

I hope I was clear,
Thanks for your help!
az38
Community Champion
Community Champion

Hi @AleFVG 

what if you will have a few years in the table? and why does 

L2222 BB

has 15 in your column?

 

anyway, try column

Avg unit last month = 
var _lastMonth = CALCULATE(MAX('Table'[Month]), ALLEXCEPT('Table', 'Table'[Item]))
RETURN
CALCULATE(MAX('Table'[Avg price unit]), ALLEXCEPT('Table', 'Table'[Item]), 'Table'[Month]=_lastMonth)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
amitchandak
Super User
Super User

@AleFVG , Try both as new columns

last month = maxx(filter(Table, [Item]=earlier([Item]) && [Month]<earlier([Month])),[Month])

Avg unit last month =maxx(filter(Table, [Item]=earlier([Item]) && [Month]<earlier([last month ])),[ Avg price unit])

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
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!

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.