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.
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:
Product | Price |
Pencil | 2.00 |
Crayon | null |
Backpack | 10,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!
Solved! Go to Solution.
maybe you want a measure, instead of calculated column
NewMeasure=SUMX(Products,COUNTROWS(RELATEDTABLE(orders))*Products[Price])
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])
if you are adding calculated column in Products table, try this code
NewColumn=COUNTROWS(RELATEDTABLE(Orders))*Products[Price]
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
39 | |
21 | |
21 | |
14 | |
13 |
User | Count |
---|---|
44 | |
32 | |
30 | |
18 | |
17 |