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

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.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.