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
smartpug
New Member

Calculating values based on two tables

Hi all,

I am a super beginner and have the following case:

Problem: 

We have two tables: Products and Orders. They have a One-To-Many relationship so one Product might be in a few orders - a classic case. Product has a 'Price' column and an important note is that it's not a mandatory field - some products have the price and some products have it blank. I want to calculate a total value for each product based on the row count of related rows from the 'Orders' table. Formula like TotalValue = Product.Price * CountRows(Orders) where Orders.Product = Product

 

Example:
Products:

ProductPrice
Pencil2.00
Crayonnull
Backpack10,00

 

If in Orders we have two Pencils - we will get a total of 4.00, if we have 5 Backpacks - we get a total of 50, and Crayon is skipped.

These values will be displayed to the user as figures for each product having a price and also as a sum of all totals.

 

I bet it's super easy but I'm also an absolute beginner in Power BI and DAX so I would be really thankful for any help!

1 ACCEPTED SOLUTION

maybe you want a measure, instead of calculated column

NewMeasure=SUMX(Products,COUNTROWS(RELATEDTABLE(orders))*Products[Price])

View solution in original post

5 REPLIES 5
smartpug
New Member

Hi,
Thanks for answering. Tried this and unfortunately, I get this error:
"A single value for column 'Price' in table 'Products' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

 

The problem is - when I was using aggregation for the 'Price' - e.g. Max('Price') - it was getting the highest 'Price' from the table and just multiplied it by all rows. 

maybe you want a measure, instead of calculated column

NewMeasure=SUMX(Products,COUNTROWS(RELATEDTABLE(orders))*Products[Price])

Yes, this is exactly what I need, thanks! Is it possible to modify this DAX to filter RELATEDTABLE(orders) to include only orders.DeliveryType = "Pickup"?

NewMeasure=SUMX(Products,COUNTROWS(FILTER(RELATEDTABLE(orders),orders[DeliveryType]="Pickup"))*Products[Price])

wdx223_Daniel
Super User
Super User

if you are adding calculated column in Products table, try this code

NewColumn=COUNTROWS(RELATEDTABLE(Orders))*Products[Price]

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.

Top Solution Authors