Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Suyheng
Frequent Visitor

Compare two rows based on criteria in power query and power bi

Dear All,

 

I need your help for geting the result column as below:

I want to have a power query and a dax code to get the result column based on Criteria Column.

if the criteria column contain "cash" then the result column return cash for the same TranCode Column and the rest

that don't meet the Criteria Column return null.

Please noted that for large data set I can merge column to get the result in power query but the pefromance is too slow and i want a better way for power query code that avoid merging column.

 

TranCodeAcc DecriptionCriteriaResult
A1ExpnullCash
A1CashCashCash
B1Expnullnull
B1Payablenullnull
C1Expnullnull
C1Payablenullnull
D1ExpCashCash
D1CashnullCash

Appriciate for you kind help.

 

Best regards,

Heng

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

This calculated column formula works

 

=if(CALCULATE(CALCULATE(COUNTROWS(Data),Data[Criteria]="Cash"),FILTER(Data,Data[TranCode]=EARLIER(Data[TranCode])))=1,"Cash",BLANK())

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

 

This calculated column formula works

 

=if(CALCULATE(CALCULATE(COUNTROWS(Data),Data[Criteria]="Cash"),FILTER(Data,Data[TranCode]=EARLIER(Data[TranCode])))=1,"Cash",BLANK())

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Dear Ashish_Mathur,

Very nice formula.

 

Do you have any solution in power query?

 

Thanks for your help.

 

Best regards,

Heng

Hi,

 

Thank you.  No i do not know how to solve this in the Query Editor.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors