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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Dayna
Helper V
Helper V

Measure for a 'basic' calculation

Hello,

 

Apologies, I'm still getting used to the syntax in PowerBI so this may sound like a daft question!


I have two tables, one listing all components with their associated weight, the other specifying the quantity of the item by a product. For example:

Components:

TypeIDWeight
TypeA1231.2
TypeA2341.3
TypeB3451.5
TypeC456

2.1

 

ComponentLevel:

TypeIdLevelQuantity
123Pack1
234Pack2
345Pallet1
456Pallet1

 

What I want to do is two things:

1) Provide the weight of the item (i.e. weight * quantity) by item id

Expected Results:
TypeIdTotal Weight
1231.2
2342.6
3451.5
4562.1

2) Sum of the weights per level (i.e. Pack).

Expected Results
LevelWeight
Pack3.8
Pallet3.6

 

 

How would I do this using measures, please?

 

I started with something like this, but I think when it goes a level, it'll be wrong as it'll use the max value across all my items

 

Pack Level Weight (inc. Quantity) = 
calculate(max('Product Routing Components'[Quantity])*max(Components[Weight]),'Product Routing Components'[PackLevel] = "Pack")

 

 

if someone could help, or explain how I should go about this, it would be appreciated. I'm new to PowerBI but used QlikView for a while, so the syntax is throwing me off slightly!

 

Many thanks,

Dayna

2 ACCEPTED SOLUTIONS
vojtechsima
Memorable Member
Memorable Member

Hi, @Dayna,
One measure to rule them all:

TotalWeight = 
var VirtualTable = SUMMARIZE(Components, ComponentLevel[Quantity], Components[Weight], ComponentLevel[Level], Components[ID])
var FinalWeight = SUMX(VirtualTable, ComponentLevel[Quantity] * Components[Weight])
return FinalWeight

vojtechsima_0-1653403846712.png

Given you have an active Active Relationship between TypeID and ID (ComponentLevel, Components), create a virtual table inside measure using SUMMARIZE, then iterate through this new table and you get you result for both your cases.

View solution in original post

Hi, @Dayna,
I believe with this setup you can achieve your desired outcome, just bring every needed column to the Summarize and do your calculations.

View solution in original post

4 REPLIES 4
Dayna
Helper V
Helper V

Thank you @vojtechsima for all your help 🙂 

vojtechsima
Memorable Member
Memorable Member

Hi, @Dayna,
One measure to rule them all:

TotalWeight = 
var VirtualTable = SUMMARIZE(Components, ComponentLevel[Quantity], Components[Weight], ComponentLevel[Level], Components[ID])
var FinalWeight = SUMX(VirtualTable, ComponentLevel[Quantity] * Components[Weight])
return FinalWeight

vojtechsima_0-1653403846712.png

Given you have an active Active Relationship between TypeID and ID (ComponentLevel, Components), create a virtual table inside measure using SUMMARIZE, then iterate through this new table and you get you result for both your cases.

Hi @vojtechsima 

 

Oh that's great, thank you! Summarize looks to be a very interesting function that I should look into more..!

 

If it wanted to expand this further and do a calculation based on another field from a different table based on the Level, would this be possible?

 

So a couple of links down the chain:

Dayna_0-1653473330766.png

 

Where PackLevel = 'Pack', I'd like to multiple this quantity by the field in 'UM - SU - MU' for um_conv. All else returns the normal value.

 

Is this possible to extend further? I know this table is three links further in my relationship model.

 

Many thanks for all your help so far.

 

Kind Regards,

Dayna

 

Hi, @Dayna,
I believe with this setup you can achieve your desired outcome, just bring every needed column to the Summarize and do your calculations.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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