Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hello, I am trying to calculate medium number of price with weighting to resale quantity, example as below:
| Price | Quantity | % | Price Chosen |
| 1 | 100 | 10% | |
| 1.2 | 500 | 60% | %>=0.5, Price=1.2 |
| 1.4 | 300 | 90% | |
| 1.5 | 100 | 100% |
However, i encounter query exceeded available resources, i know the issue is from measure 4, but i don't know how to optimize it
or any other solution to get the same result.
measure 1
Solved! Go to Solution.
Hi @wanglibin,
Why you get “query exceeded resources”?
Your measure 4 is very expensive because:
That causes nested scans of the same table = memory explosion.
Correct & optimized approach (single measure, no % column)
Goal: Find the lowest price where cumulative quantity ≥ 50% of total
Optimized Measure (SAFE & FAST):
---DAX---
50% Vol Price =
VAR TotalQty =
CALCULATE (
SUM ( 'Summarized POS'[Resale Qty] ),
ALLSELECTED ( 'Summarized POS' )
)
VAR TargetQty = TotalQty * 0.5
VAR PriceTable =
ADDCOLUMNS (
VALUES ( 'Summarized POS'[Price$] ),
"CumQty",
CALCULATE (
SUM ( 'Summarized POS'[Resale Qty] ),
FILTER (
ALLSELECTED ( 'Summarized POS' ),
'Summarized POS'[Price$]
<= EARLIER ( 'Summarized POS'[Price$] )
)
)
)
RETURN
MINX (
FILTER ( PriceTable, [CumQty] >= TargetQty ),
'Summarized POS'[Price$]
)
---DAX---
Why this works?
This is the standard weighted median pattern in Power BI.
What to remove:
Always Remember:
=================================================================
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Jaywant Thorat | MCT | Data Analytics Coach | Super User
LinkedIn: https://www.linkedin.com/in/jaywantthorat/
Join #MissionPowerBIBharat: https://tinyurl.com/JoinMissionPowerBIBharat
#MissionPowerBIBharat
LIVE with Jaywant Thorat
I am not exactly sure about your data but it is obvious that you’re hitting the limit because measure 4 filters a large table using another measure. Instead that you could use a single measure as below logic:
50% Vol Price =
VAR TotQty =
SUM ( 'Summarized POS'[Resale Qty] )
VAR PriceQty =
SUMMARIZE (
'Summarized POS',
'Summarized POS'[Price$],
"Qty", SUM ( 'Summarized POS'[Resale Qty] )
)
VAR WithCum =
ADDCOLUMNS (
PriceQty,
"CumQty",
VAR p = [Price$]
RETURN
SUMX ( FILTER ( PriceQty, [Price$] <= p ), [Qty] )
)
RETURN
MINX (
FILTER ( WithCum, DIVIDE ( [CumQty], TotQty ) >= 0.5 ),
[Price$]
)
I am not exactly sure about your data but it is obvious that you’re hitting the limit because measure 4 filters a large table using another measure. Instead that you could use a single measure as below logic:
50% Vol Price =
VAR TotQty =
SUM ( 'Summarized POS'[Resale Qty] )
VAR PriceQty =
SUMMARIZE (
'Summarized POS',
'Summarized POS'[Price$],
"Qty", SUM ( 'Summarized POS'[Resale Qty] )
)
VAR WithCum =
ADDCOLUMNS (
PriceQty,
"CumQty",
VAR p = [Price$]
RETURN
SUMX ( FILTER ( PriceQty, [Price$] <= p ), [Qty] )
)
RETURN
MINX (
FILTER ( WithCum, DIVIDE ( [CumQty], TotQty ) >= 0.5 ),
[Price$]
)
Hi @wanglibin ,
Thanks for reaching out to the Microsoft fabric community forum.
I would also take a moment to thank @cengizhanarslan , for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you
Best Regards,
Community Support Team
Hi @wanglibin ,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you
Best Regards,
Community Support Team
Hi @wanglibin,
Why you get “query exceeded resources”?
Your measure 4 is very expensive because:
That causes nested scans of the same table = memory explosion.
Correct & optimized approach (single measure, no % column)
Goal: Find the lowest price where cumulative quantity ≥ 50% of total
Optimized Measure (SAFE & FAST):
---DAX---
50% Vol Price =
VAR TotalQty =
CALCULATE (
SUM ( 'Summarized POS'[Resale Qty] ),
ALLSELECTED ( 'Summarized POS' )
)
VAR TargetQty = TotalQty * 0.5
VAR PriceTable =
ADDCOLUMNS (
VALUES ( 'Summarized POS'[Price$] ),
"CumQty",
CALCULATE (
SUM ( 'Summarized POS'[Resale Qty] ),
FILTER (
ALLSELECTED ( 'Summarized POS' ),
'Summarized POS'[Price$]
<= EARLIER ( 'Summarized POS'[Price$] )
)
)
)
RETURN
MINX (
FILTER ( PriceTable, [CumQty] >= TargetQty ),
'Summarized POS'[Price$]
)
---DAX---
Why this works?
This is the standard weighted median pattern in Power BI.
What to remove:
Always Remember:
=================================================================
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Jaywant Thorat | MCT | Data Analytics Coach | Super User
LinkedIn: https://www.linkedin.com/in/jaywantthorat/
Join #MissionPowerBIBharat: https://tinyurl.com/JoinMissionPowerBIBharat
#MissionPowerBIBharat
LIVE with Jaywant Thorat
| User | Count |
|---|---|
| 57 | |
| 44 | |
| 32 | |
| 16 | |
| 14 |
| User | Count |
|---|---|
| 82 | |
| 66 | |
| 42 | |
| 27 | |
| 25 |