Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello,
I would like to fill baskets with products to make them as "full" as possible based on volume. For simplicity, lets ignore quantity and other parameters as I account for those elsewhere already.
I have a dataset that looks somewhat like this:
Product | Volume |
A | 4 |
B | 3 |
C | 2,5 |
D | 2 |
Lets say there is a basket with maximum volume of 10. I need to make a calculation that would output the following resulting in an order of 9,5:
Product | Volume | Order |
A | 4 | 4 |
B | 3 | 3 |
C | 2,5 | 2,5 |
D | 2 |
This should be done in DAX - probably using a calculated table?
Thank you for any suggestions!
Solved! Go to Solution.
Hi @jan_buzek
You can create a Measure as the following.
Fill Basket =
VAR basket_size = 10
VAR total_vol =
CALCULATE ( SUM ( 'Table'[Volume] ), ALL ( 'Table' ) )
VAR accmulate_vol =
CALCULATE (
SUM ( 'Table'[Volume] ),
FILTER ( ALL ( 'Table' ), 'Table'[Volume] >= MAX ( 'Table'[Volume] ) )
)
VAR inter =
CALCULATE (
SUM ( 'Table'[Volume] ),
FILTER ( 'Table', accmulate_vol < basket_size )
)
VAR res =
IF ( HASONEVALUE ( 'Table'[Product] ), inter, basket_size )
RETURN
IF ( total_vol <= basket_size, SUMX ( 'Table', 'Table'[Volume] ), res )
The result looks like this:
For more details, you can refer the attached pbix file.
Best Regards
Caiyun Zheng
Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @jan_buzek
You can create a Measure as the following.
Fill Basket =
VAR basket_size = 10
VAR total_vol =
CALCULATE ( SUM ( 'Table'[Volume] ), ALL ( 'Table' ) )
VAR accmulate_vol =
CALCULATE (
SUM ( 'Table'[Volume] ),
FILTER ( ALL ( 'Table' ), 'Table'[Volume] >= MAX ( 'Table'[Volume] ) )
)
VAR inter =
CALCULATE (
SUM ( 'Table'[Volume] ),
FILTER ( 'Table', accmulate_vol < basket_size )
)
VAR res =
IF ( HASONEVALUE ( 'Table'[Product] ), inter, basket_size )
RETURN
IF ( total_vol <= basket_size, SUMX ( 'Table', 'Table'[Volume] ), res )
The result looks like this:
For more details, you can refer the attached pbix file.
Best Regards
Caiyun Zheng
Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@jan_buzek
I got the idea but your data is not as simple as this sample I believe. Can you share a sample that is much closer to the actual as I think the logic should be applicable at the end.
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
113 | |
81 | |
45 | |
42 | |
27 |
User | Count |
---|---|
182 | |
83 | |
70 | |
48 | |
45 |