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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
vpastor
Frequent Visitor

Query with row values

Hello everyone

 

I am desperate and do not know how I can realize the following:

 

I have two tables:

 

G_L Entry (1 table)

GL Account NoAmount
1700005000 €
2100003500 €
5200001000 €
5202222000 €
1740005000 €
5200008000 €
5500001000 €

 

Acc_ Schedule Line (2 table)

Totaling
170|520|174|5200|5500

 

The totaling field is a text string composed of several values, for example (170|520|174|524|5200|5500).

I need to make a formula that is able to read those values and add the "Amount" when the "GL Account No" starts with one of the values we have read from the "Totaling" column.

 

For example this measure return this:

22.000 €

 

Thank you very much to all of you.

 

Regards
Vicente

 

1 ACCEPTED SOLUTION

Hi @vpastor, check this:

 

Result

dufoq3_0-1720692895811.png

 

let
    Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ3AAIlHSVTIKXwqGmNUqxOtJKRIVTU2BRJ1NQIKmpogCpqZGQEFDVCFjU0N8FiLtwECxRRUwxzYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"GL Account No" = _t, Amount = _t]),
    Table1ChangedType = Table.TransformColumnTypes(Table1,{{"GL Account No", type text},{"Amount", type number}}, "sk-SK"),
    Table1Buffered = Table.Buffer(Table1ChangedType),
    Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ3qDE1MqgxNDcB0UCOqYGBUqxOtJKRIVgUzDYEShgaGSvFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Totaling = _t]),
    Ad_SumAmount = Table.AddColumn(Table2, "Sum Amount", each 
        [ a = Text.Split([Totaling], "|"),
          b = Table.SelectRows(Table1Buffered, (x)=> List.Contains(a, x[GL Account No], (y,z)=> Text.StartsWith(z,y)))[Amount],
          c = List.Sum(b) ?? 0
        ][c], type number)
in
    Ad_SumAmount

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

7 REPLIES 7
dufoq3
Super User
Super User

Hi @vpastor, you're welcome 😉

 

let
    Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ3AAIlHSVTIKXwqGmNUqxOtJKRIVTU2BRJ1NQIKmpogCpqZGQEFDVCFjU0N8FiLtwECxRRUwxzYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"GL Account No" = _t, Amount = _t]),
    Table1ChangedType = Table.TransformColumnTypes(Table1,{{"GL Account No", type text},{"Amount", type number}}),
    Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ3qDE1MqgxNDcB0UCOqYGBUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Totaling = _t]),
    Table2Split = Table.TransformColumns(Table2, {{"Totaling", each Text.Split(_, "|"), type list}}),
    Table2ToListBuffered = List.Buffer(List.Combine(Table2Split[Totaling])),
    StepBack = Table1ChangedType,
    Ad_Check = Table.AddColumn(StepBack, "Check", each if List.Contains(Table2ToListBuffered, [GL Account No], (x,y)=> Text.StartsWith(y, x)) then 1 else 0, Int64.Type),
    FilteredRows = Table.SelectRows(Ad_Check, each ([Check] = 1)),
    CalculatedSum = List.Sum(FilteredRows[Amount])
in
    CalculatedSum

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi @dufoq3 
Thank you very much for your quick and efficient response.

I have verified the answer with the example code and it is perfect.
The problem I have is that table 2 "Acc_ Schedule Line" has not only one row, it is composed of multiple rows. For example:

Acc_ Schedule Line (2 table)

Totaling
170|520|174|5200|5500
100|123
70001|70002|70003
421000|422000


Could you please modify the query to work with the attached example?


I suppose we will have to create a column in table 2 that returns the sum of "GL Account No" according to the values of "Totaling".
Thank you very much

 

Regards

Vicente

Hi, my query should work also with multiple "totaling" rows. Have you checked it?


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi @dufoq3,

Yes, your query work corretly, but i need this result for example:

 

G_L Entry (1 table)

GL Account NoAmount
1700005000 €
2100003500 €
5200001000 €
5202222000 €
1740005000 €
5200008000 €
5500001000 €

 

Acc_ Schedule Line (2 table)

TotalingSum Amount
170|520|174|5200|550022.000 €
210|1748500 €
100|1230 €

 

I would be very grateful if you could adapt the query to my needs.

 

Thank you so much!

 

Vicente

Hi @vpastor, check this:

 

Result

dufoq3_0-1720692895811.png

 

let
    Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ3AAIlHSVTIKXwqGmNUqxOtJKRIVTU2BRJ1NQIKmpogCpqZGQEFDVCFjU0N8FiLtwECxRRUwxzYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"GL Account No" = _t, Amount = _t]),
    Table1ChangedType = Table.TransformColumnTypes(Table1,{{"GL Account No", type text},{"Amount", type number}}, "sk-SK"),
    Table1Buffered = Table.Buffer(Table1ChangedType),
    Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ3qDE1MqgxNDcB0UCOqYGBUqxOtJKRIVgUzDYEShgaGSvFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Totaling = _t]),
    Ad_SumAmount = Table.AddColumn(Table2, "Sum Amount", each 
        [ a = Text.Split([Totaling], "|"),
          b = Table.SelectRows(Table1Buffered, (x)=> List.Contains(a, x[GL Account No], (y,z)=> Text.StartsWith(z,y)))[Amount],
          c = List.Sum(b) ?? 0
        ][c], type number)
in
    Ad_SumAmount

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi @dufoq3,

 

I'm afraid not, when I copy your answer it does not work correctly.

vpastor_0-1720772265730.png

 

This is the error:

vpastor_1-1720772401770.png

 

Thank you so much!

 

 

I've edited code above. Try it now.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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