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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Vinothsusai
Helper III
Helper III

Problem in ContainsStringExact function. It does not compare exact value.

Hi,

I am new into power BI. I have formula like 11 + 12 . i just need to sum values of 11th id amount and 12th id amount values as below screen shot. But it retreives 1th id amount value. Please advise. In the scrrenshot I explained clearly. Please advise.30.png

 

Thanks

Vinoth SUSAINATHAN

 

1 ACCEPTED SOLUTION

Hi @Vinothsusai 

Create a column

formula_alter = IF([Formula]<>BLANK(),[Formula]&"+")

Then create a measure

Measure 2 =
VAR MAXF =
    MAX ( Table1[formula_alter] )
RETURN
    IF (
        MAXF = BLANK (),
        SUM ( Table1[Amount] ),
        CALCULATE (
            SUM ( Table1[Amount] ),
            FILTER ( ALL ( Table1 ), CONTAINSSTRINGEXACT ( MAXF, "D" & [LineID] & "+" ) )
        )
    )

4.png

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @Vinothsusai 

Do you have a dataset as below?

"Formula" ,"Total amount" and "amount" in your pictures are created by you based on the dataset, right?

line id main amount
1 1
2  
3 2
4 3
5  
6  
7 6
8 7
9  
10 8
11 9
12  

 

Could you give the calculation rule for "Formula" ,"Total amount" and "amount"?

You could add expected values in my simple data example above and share here.

 

Best Regards
Maggie

 

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

Hi,

I am expecting the output like below. Please help me

32.png

Data

LineIDAmountFormulaTotal Amount
1100 ? 
250D1+D2? 
3200D1+D3? 
470D2+D4? 
520D1+D2+D4? 
610D4+D6? 
720D5+D6+D7? 
10110D5+D6+D7? 
11130D10+D11? 

 

When i use my measure,

Measure Formula = VAR maxf =
MAX ( HANGeneralJournals_Remodify[ReportLayout.Formula])

RETURN
IF ( maxf = BLANK () ,SUM(HANGeneralJournals_Remodify[Custom Main Amount]), CALCULATE(SUM(HANGeneralJournals_Remodify[Custom Main Amount]),FILTER(ALL(HANGeneralJournals_Remodify),ISBLANK([ReportLayout.Line ID])=FALSE()&&CONTAINSSTRINGEXACT(maxf,"D"&[ReportLayout.Line ID]))))
 
I got the wrong result for the formula (D10 + D11) in the row Line ID 11, the measure taken D1+D1 instead of D10 + D11. Please see the below screen shot.
 
LineIDAmountFormulaTotal Amount
1100 100 
250D1+D2150 
3200D1+D3300 
470D2+D4120 
520D1+D2+D4220 
610D4+D680 
720D5+D6+D750 
10110D5+D6+D750 
11130D10+D11200 

 

Instead of get 240 (D10+D11), I am getting 200(D1+D1) in lineitemID 11 by using my measure.

Please advise.

Hi @Vinothsusai 

Create a column

formula_alter = IF([Formula]<>BLANK(),[Formula]&"+")

Then create a measure

Measure 2 =
VAR MAXF =
    MAX ( Table1[formula_alter] )
RETURN
    IF (
        MAXF = BLANK (),
        SUM ( Table1[Amount] ),
        CALCULATE (
            SUM ( Table1[Amount] ),
            FILTER ( ALL ( Table1 ), CONTAINSSTRINGEXACT ( MAXF, "D" & [LineID] & "+" ) )
        )
    )

4.png

Best Regards
Maggie

 

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

Hi,

Thank you for your reply.

Yes. I have a dataset as mentioned below.

Line ID  GroupAccount  GroupAccountDescription  MainAccount  ReportLayout.Formula  Amount  TotalAmount

1R701000Gross sales70100000 1925702 
3R708001Commissions to retail partner65100000D31952934 
35R641001Chef64110001 -75.2 
36R641002Assistant64110002D3+D35+D36111478 
40R645001Chef64510001D1+D36-1698.72 
41R645002Assistant64510002 21069.99 
46R695000Subsidies64910000 62371.96 
47R621000Temporary worker62110000D40+D471920000 
48R647000Medical fees64750000D41+D47+D487595.4 
50R615001Cleaning Products60222000 499 
55R615005Maintenance contract (preventive)61560000 140157.9 
60R623003Other marketing PoS62310000D41+D47+D48+D607686.54 
62R616000Insurance61610000 13146.64 
63R622001Controls62260005D60+D621060 
68R613001Lease expense - External party61320001 35624.28 
136R623530Agency Compensation62300000D68+D13688372.66 
137R623540Catalogues / Brochures62360000 180617.9 
139R628500Others62310000D137+D1397686.54 
142R622620Audit fees62260003 2700 
155R622820Official Acts62270001 23195.7 
164R613100Lease expense61320001 35624.28 

Here i need to find Total amount based on the formula.

@v-lili6-msfthad already provided a solution for me. Please see the below ticket url. In the formula I have a problem in ContainsStringExact function

Measure Formula = VAR maxf =
MAX ( HANGeneralJournals_Remodify[ReportLayout.Formula])

RETURN
IF ( maxf = BLANK () ,SUM(HANGeneralJournals_Remodify[Custom Main Amount]), CALCULATE(SUM(HANGeneralJournals_Remodify[Custom Main Amount]),FILTER(ALL(HANGeneralJournals_Remodify),ISBLANK([ReportLayout.Line ID])=FALSE()&&CONTAINSSTRINGEXACT(maxf,"D"&([ReportLayout.Line ID])))))

 

Formula field is a string type. While extract the line ID from the formula (for ex: D11 + D12 = 11 + 12. ID 11th Amount value is 0 and ID 12th Amount value is 0 so the total is 0 but the result seems wrong as retrieved ID 1th Amount Value because I am using ContainsStringExact function when it compare D11, it takes as D1 . D1 string with in D11)30.png

 

To resolve this, I have used another formula. But it works serial IDs for ex: D1+D2+D3+D4+D5 but not in random Ids like D5+D7+ D9+D20 because the formula is looping serially.

Measure Formula = VAR maxf =

    MAX ( HANGeneralJournals_Remodify[ReportLayout.Formula] )

VAR sub = SUBSTITUTE ( maxf, "D", "" )

VAR no =

    LEN (maxf) - LEN ( SUBSTITUTE ( sub, "+", "" ) )

VAR a =

    CALCULATE (

        SUM ( HANGeneralJournals_Remodify[Custom Main Amount]  ),

        FILTER (

            ALL ( HANGeneralJournals_Remodify ),

            HANGeneralJournals_Remodify[ReportLayout.Line ID] <= MAX ( HANGeneralJournals_Remodify[ReportLayout.Line ID]  )

                && HANGeneralJournals_Remodify[ReportLayout.Line ID]

                    >= MAX ( HANGeneralJournals_Remodify[ReportLayout.Line ID]  ) - no

        )

    )

RETURN

    IF ( maxf = BLANK (),SUM (HANGeneralJournals_Remodify[Custom Main Amount]) , a )

 

Please advise

Thanks

Vinoth S

Helpful resources

Announcements
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.