Forum Discussion
Query Exceeds
I have created a calculated column like this
A=
IF (
ISBLANK('Fact'[Inv No]),
'Fact'[Amt],
IF (
'Fact'[account_id] = "AP",
'Fact'[local_amt],
'Fact'[local_amt] * -1
)
)
After this i have created a measure on top of it Measure = SUM(A)
Now with using this i have to create other calculated column B like
B= IF(Measure>0,Measure,0)
But when I drag this in table query exceeds resources. I am not sure why this is happening
- Anonymous8 months ago
Hi SudhanshuD4512,
Thank you for reaching out to the Microsoft Fabric Forum Community, and special thanks to Hans-Georg_Puls , kushanNa , syahmisi98 and amitchandak for prompt and helpful responses.
I’ve tried to reproduce the scenario using the M code below. Please review and adjust it according to your data source. If the issue still persists, feel free to share more details, and we’ll be happy to assist further.
Thanks & Regards,
Prasanna Kumar
11 Replies
- rohit1991Super User
Hii SudhanshuD4512
Your query exceeds because you are using a measure inside a calculated column, which forces Power BI to recalculate the entire measure for every row, creating a very expensive row-by-row evaluation. Calculated columns cannot depend on measures and this pattern always causes performance issues. Instead, put all logic in a measure only, for example B = IF([Measure] > 0, [Measure], 0), and remove the second calculated column. Measures calculate at query time and will not cause “query exceeds resources,” but calculated columns with measures will.
- SudhanshuD4512Frequent Visitor
I have tried that as well but same issue is there
- amitchandakSuper User
SudhanshuD4512 , Unless this calculation has to change based on the visual row, you can have this as a row of a table, like
Change the calculated column like
A= Var _1 = IF ( ISBLANK('Fact'[Inv No]), 'Fact'[Amt],
IF (
'Fact'[account_id] = "AP",
'Fact'[local_amt],
'Fact'[local_amt] * -1
))
return IF(_1>0,_1,0)
- AnonymousNot applicable
Hi SudhanshuD4512,
Thank you for reaching out to the Microsoft Fabric Forum Community, and special thanks to Hans-Georg_Puls , kushanNa , syahmisi98 and amitchandak for prompt and helpful responses.
I’ve tried to reproduce the scenario using the M code below. Please review and adjust it according to your data source. If the issue still persists, feel free to share more details, and we’ll be happy to assist further.
Thanks & Regards,
Prasanna Kumar
- syahmisi98Advocate I
You’re using a measure inside a calculated column. That forces Power BI to evaluate the measure (which works in filter context) for every single row during refresh, and then again in visuals.
- Move your calculated column A to Power Query- Create B as a measure instead of calculated column and then add the measure to your table
Did I answer your question? Mark my post as a solution! Appreciate your Kudos
- kushanNaSuper User
Is it possible to get a sample PBIX file with the issue you are having? Maybe create a small table with test data and try to recreate the issue?
- Hans-Georg_PulsSuper User
Hi SudhanshuD4512 ,
as rohit1991 already mentioned a calculated column is something static it cannot depend on a measure that is something dynamic.
I created a sample data set using same column and table names you mentioned:
A measure that does your desired calculation should look like the following one:
B =VAR _sum = SUMX('Fact',IF('Fact'[Inv No] = "",'Fact'[Amt],IF ('Fact'[account_id] = "AP",'Fact'[local_amt],'Fact'[local_amt] * -1)))RETURNIF(_sum > 0, _sum, 0)Please note that blank and empty string are not the same thing. Depending on the type of your account_id column it could be necessary to replace the condition 'Fact'[account_id] = "AP" by something different. I assumed that it is a string.If you are interested in the details of blank and empty strings and ISBLANK see for example the DAX guideHope that helps! - SudhanshuD4512Frequent Visitor
Net Activity =
IF (
ISBLANK('Fact'[Inv No]),
'Fact'[Amt],
IF (
'Fact'[account_id] = "AP",
'Fact'[local_amt],
'Fact'[local_amt] * -1
)
)
Debit is calculated as if we sum net activity, if(net activity>0,net activity,0)
Credit if(net activity<0,net activity,0)*-1- SudhanshuD4512Frequent Visitor
Inv Num AccountID Local Amount Amt 1000 AP 300 100 1000 AP -350 200 1000 AP 400 200 input
Output below i wantInv Num AccountID Net Activity Debits Credits 1000 AP 350 350 0
- AnonymousNot applicable
Hi SudhanshuD4512,
Just following up to see if the Response provided was helpful in addressing the issue. if the issue still persists Feel free to reach out if you need any further clarification or assistance.
Best regards,
Prasanna Kumar - AnonymousNot applicable
Hi @SudhanshuD4512,
Just following up to see if the Response provided was helpful in addressing the issue. if the issue still persists Feel free to reach out if you need any further clarification or assistance.
Best regards,
Prasanna Kumar