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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
MikeFo
Frequent Visitor

Group by & Find/Replace?

Hi all

 

I have issues getting the right query for the scenario below. I appreciate it´s rather complicated to understand, but let me give it a try.

 

Table Name: Register

 

Credit NumberCurrencyCredit
1ABCEUR2,000
1ABCUSD25,000
1ABCHKD50,000
2HIJGBP35,000
3KLMHKD125,000

 

Conditions:

If 1 Credit Number has a Currency = EUR && a Currency = USD,

and if Credit for EUR is smaller than Credit for USD,

then I want to keep Credit for EUR and make Credit for USD as 0,

but if Credit for EUR is bigger than Credit for USD, I want to make both Credit as 0

if none of the above, keep Credit as is

 

Expected Outcome:

Credit Number CurrencyCredit
1ABCEUR2,000
1ABCUSD0
1ABCHKD50,000
2HIJGBP35,000
3KLMHKD125,000

 

Appreciate your thoughts!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@MikeFo , Create a new column

new Credit =
Var _Eur = maxx(filter(Table, [Credit Number]=earlier( [Credit Number]) && [Currency]= "EUR"), [Credit])
Var _USD = maxx(filter(Table, [Credit Number]=earlier( [Credit Number]) && [Currency]= "USD"), [Credit])
Switch( True(),
_Eur > _USD && [Currency] in {"EUR", "USD"}, 0,
_Eur < _USD && [Currency] in {"USD"}, 0,
[Credit])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@MikeFo , Create a new column

new Credit =
Var _Eur = maxx(filter(Table, [Credit Number]=earlier( [Credit Number]) && [Currency]= "EUR"), [Credit])
Var _USD = maxx(filter(Table, [Credit Number]=earlier( [Credit Number]) && [Currency]= "USD"), [Credit])
Switch( True(),
_Eur > _USD && [Currency] in {"EUR", "USD"}, 0,
_Eur < _USD && [Currency] in {"USD"}, 0,
[Credit])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks, this helped. 

 

How would I apply this in the "Transform Data" view i.e. before the Close & Apply step?

Helpful resources

Announcements
December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.