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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
fyip
Frequent Visitor

Lookup sum via substring?

 

I'm trying to create a table where it looks an accounting journal and take:

 

sum(101010) - sum(201010) .. to show the profit and margin....

I want to iternate through all the accounts with "10" prefix and then minus their corresponding of "20" prefix.

i.e. 101010 = income          and    201010 = expense

 

I'm trying the below logic but it's wrong... i'm a bit stuck.. .. can any body help and check what I can do?

 

Amount (Profit) = CALCULATE(sum('AccJrn'[amount]), 'AccChart'[accNo]=CONCATENATE("20",right('AccChart'[accNo], 4)))

 

profitandloss.PNG

1 ACCEPTED SOLUTION
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @fyip,

Based on my test, you can refer to below steps:

1.I have entered some sample data:

B1.PNG

2.Create two measures.

Measure 4 = var s10= CALCULATE(SUM(Table1[Amount]),Table1[Acc No]=101010)

var s1020 =CALCULATE(SUM(Table1[Amount]),Table1[Acc No]=101020)

var s2010 = CALCULATE(SUM(Table1[Amount]),Table1[Acc No] = 201010)

var s201020 = CALCULATE(SUM(Table1[Amount]),Table1[Acc No]=201020)

return

IF(MAX(Table1[Acc No])=101010,s10-s2010,IF(MAX(Table1[Acc No])=101020,s1020-s201020,BLANK()))

 

mar = [Measure 4]/SUM(Table1[Amount])

3.Create a Table visual and add the related field and you can see the result.

B2.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/kfcegjy7o1pnvp4/Lookup%20sum%20via%20substring.pbix?dl=0

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @fyip,

could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @fyip,

Based on my test, you can refer to below steps:

1.I have entered some sample data:

B1.PNG

2.Create two measures.

Measure 4 = var s10= CALCULATE(SUM(Table1[Amount]),Table1[Acc No]=101010)

var s1020 =CALCULATE(SUM(Table1[Amount]),Table1[Acc No]=101020)

var s2010 = CALCULATE(SUM(Table1[Amount]),Table1[Acc No] = 201010)

var s201020 = CALCULATE(SUM(Table1[Amount]),Table1[Acc No]=201020)

return

IF(MAX(Table1[Acc No])=101010,s10-s2010,IF(MAX(Table1[Acc No])=101020,s1020-s201020,BLANK()))

 

mar = [Measure 4]/SUM(Table1[Amount])

3.Create a Table visual and add the related field and you can see the result.

B2.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/kfcegjy7o1pnvp4/Lookup%20sum%20via%20substring.pbix?dl=0

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

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.