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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
beerock
New Member

Custom Column Help

I need to create a custom column that queries the rest of the data for a specific value

The data looks something like this

User

Call Direction

ANI(Automatic Number Identification)

DNIS(Dialed Number Identification Service)

VoiceMail

VoicMailReturned

John Smith

Inbound

123

555

Yes

 

John Smith

Inbound

345

555

No

 

John Smith

Inbound

678

555

No

 

John Smith

Outbound

555

123

No

 
 
 

 

What I am trying to do is determine if John Smith returned the voicemail received from ANI 123 in the 1st row (In the example John did call 123 in the last row)

Not sure if this a good use case for a custom column or what function to use. what I would like is VoicMailReturned column to indicate a 1 IF there was an outbound call later in the data to the number in the ANI column IF VoiceMail = Yes

 

Thanks for any help in advance

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @beerock ,

In addition to the PwerQueryKees‘s method, you can also try adding a custom column:
First add an Index column:

vjunyantmsft_0-1723618945121.png

Then use this M code to add a custom column:

vjunyantmsft_1-1723619007009.png

let 
        currentUser = [User], 
        currentDnis = [#"DNIS(Dialed Number Identification Service)"], 
        currentVoiceMailNo = [VoiceMail] = "No", 
        currentIndex = [Index]
    in 
        if currentVoiceMailNo then 
            if Table.RowCount(
                Table.SelectRows(#"Added Index", each ([#"ANI(Automatic Number Identification)"] = currentDnis and [User] = currentUser and [Index] < currentIndex))
                ) > 0 then 1 else 0
        else 0

And the final output is as below:

vjunyantmsft_2-1723619053352.png

Here is the whole M code in the Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFMIzs0syVDSUfLMS8ovzUsBsgyNjIGkqakpkIxMLVaK1cGp1NjEFK7ULx+fSjNzC7wq/UtLYEohiiCuACmNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, #"Call Direction" = _t, #"ANI(Automatic Number Identification)" = _t, #"DNIS(Dialed Number Identification Service)" = _t, VoiceMail = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ANI(Automatic Number Identification)", Int64.Type}, {"DNIS(Dialed Number Identification Service)", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    AddedCustom = Table.AddColumn(#"Added Index", "Custom Column", each let 
        currentUser = [User], 
        currentDnis = [#"DNIS(Dialed Number Identification Service)"], 
        currentVoiceMailNo = [VoiceMail] = "No", 
        currentIndex = [Index]
    in 
        if currentVoiceMailNo then 
            if Table.RowCount(
                Table.SelectRows(#"Added Index", each ([#"ANI(Automatic Number Identification)"] = currentDnis and [User] = currentUser and [Index] < currentIndex))
                ) > 0 then 1 else 0
        else 0)
in
    AddedCustom


Best Regards,
Dino Tao
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

dufoq3
Super User
Super User

Hi @beerock, another solution:

 

Output

dufoq3_0-1723665443098.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFMIzs0syVDSUfLMS8ovzUsBsgyNjIGkqakpkIxMLVaK1cGp1NjEFK7ULx+fSjNzC7wq/UtLYEohiiCuACmNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, #"Call Direction" = _t, #"ANI(Automatic Number Identification)" = _t, #"DNIS(Dialed Number Identification Service)" = _t, VoiceMail = _t]),
    AddedIndexHelper = Table.AddIndexColumn(Source, "IndexHelper", 0, 1, Int64.Type),
    Ad_VoiceMailReturned = Table.AddColumn(AddedIndexHelper, "VoiceMailReturned", each 
        [ a = Table.SelectRows(Table.Buffer(AddedIndexHelper), (x)=> x[Call Direction] = "Outbound" and x[#"DNIS(Dialed Number Identification Service)"] = [#"ANI(Automatic Number Identification)"] and x[IndexHelper] > [IndexHelper] and x[User] = [User]),
          b = if [VoiceMail] = "Yes" and not Table.IsEmpty(a) then "Yes" else "No"
        ][b], type text ),
    RemovedColumns = Table.RemoveColumns(Ad_VoiceMailReturned,{"IndexHelper"})
in
    RemovedColumns

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
YesP
Helper I
Helper I

Hi Community,

I will appretiate your help with this issue. I have the following table with two columns Order Number and Lenght. I want to create a column called "Is it a Correct Order? " If a Order number starts with "T" , "C", "V" follow by 7 digits, and has a total lengh of 14,17,20 the answer is Yes, otherwise is No.

 

YesP_0-1726789559374.png

Thank you,

Hi @YesP
1.) you should create new topic

2.) for future requests, provide sample data in usable format (not as a screenshot)

 

Output

dufoq3_0-1726819356767.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjEyNjE1M7fQNTAwMDRSitWJVnLOz0tLLUrNS05VSEtNLQaLhRlC1IGUGRlDlEE0WoKETEzBQiFALlDQEKzKQM/AEKLQ1MzC0tzCBGyFKVAULBELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Order Number" = _t]),
    Ad_Length = Table.AddColumn(Source, "Length", each Text.Length([Order Number]), type text),
    Ad_IsItACorrectOrder = Table.AddColumn(Ad_Length, "Is it a Correct Order?", each 
        [ a = List.Contains({"T", "C", "V"}, [Order Number], (x,y)=> Text.Start(y, 1) = x), //check first letter
          b = try Number.From(Text.Range([Order Number], 1, 7)) is number otherwise false, //check if followed 7 characters are digits
          c = List.Contains({14, 17, 20}, Text.Length([Order Number])), //check length
          d = if List.AllTrue({a, b, c}) then "Yes" else "No"
        ][d], type text)
in
    Ad_IsItACorrectOrder

 


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

dufoq3
Super User
Super User

Hi @beerock, another solution:

 

Output

dufoq3_0-1723665443098.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFMIzs0syVDSUfLMS8ovzUsBsgyNjIGkqakpkIxMLVaK1cGp1NjEFK7ULx+fSjNzC7wq/UtLYEohiiCuACmNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, #"Call Direction" = _t, #"ANI(Automatic Number Identification)" = _t, #"DNIS(Dialed Number Identification Service)" = _t, VoiceMail = _t]),
    AddedIndexHelper = Table.AddIndexColumn(Source, "IndexHelper", 0, 1, Int64.Type),
    Ad_VoiceMailReturned = Table.AddColumn(AddedIndexHelper, "VoiceMailReturned", each 
        [ a = Table.SelectRows(Table.Buffer(AddedIndexHelper), (x)=> x[Call Direction] = "Outbound" and x[#"DNIS(Dialed Number Identification Service)"] = [#"ANI(Automatic Number Identification)"] and x[IndexHelper] > [IndexHelper] and x[User] = [User]),
          b = if [VoiceMail] = "Yes" and not Table.IsEmpty(a) then "Yes" else "No"
        ][b], type text ),
    RemovedColumns = Table.RemoveColumns(Ad_VoiceMailReturned,{"IndexHelper"})
in
    RemovedColumns

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

Anonymous
Not applicable

Hi @beerock ,

In addition to the PwerQueryKees‘s method, you can also try adding a custom column:
First add an Index column:

vjunyantmsft_0-1723618945121.png

Then use this M code to add a custom column:

vjunyantmsft_1-1723619007009.png

let 
        currentUser = [User], 
        currentDnis = [#"DNIS(Dialed Number Identification Service)"], 
        currentVoiceMailNo = [VoiceMail] = "No", 
        currentIndex = [Index]
    in 
        if currentVoiceMailNo then 
            if Table.RowCount(
                Table.SelectRows(#"Added Index", each ([#"ANI(Automatic Number Identification)"] = currentDnis and [User] = currentUser and [Index] < currentIndex))
                ) > 0 then 1 else 0
        else 0

And the final output is as below:

vjunyantmsft_2-1723619053352.png

Here is the whole M code in the Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8srPyFMIzs0syVDSUfLMS8ovzUsBsgyNjIGkqakpkIxMLVaK1cGp1NjEFK7ULx+fSjNzC7wq/UtLYEohiiCuACmNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, #"Call Direction" = _t, #"ANI(Automatic Number Identification)" = _t, #"DNIS(Dialed Number Identification Service)" = _t, VoiceMail = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ANI(Automatic Number Identification)", Int64.Type}, {"DNIS(Dialed Number Identification Service)", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    AddedCustom = Table.AddColumn(#"Added Index", "Custom Column", each let 
        currentUser = [User], 
        currentDnis = [#"DNIS(Dialed Number Identification Service)"], 
        currentVoiceMailNo = [VoiceMail] = "No", 
        currentIndex = [Index]
    in 
        if currentVoiceMailNo then 
            if Table.RowCount(
                Table.SelectRows(#"Added Index", each ([#"ANI(Automatic Number Identification)"] = currentDnis and [User] = currentUser and [Index] < currentIndex))
                ) > 0 then 1 else 0
        else 0)
in
    AddedCustom


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PwerQueryKees
Super User
Super User

If it has to be the same agent, merge on both agent and number. Hold ctrl when selecting the columns. A little number appears on the match columns where same numbers in both table have to match.

PwerQueryKees
Super User
Super User

Would merging the table with itself matching the outbound number with the inbound number work? You can the use any table function on the merge result column to add a custom column. Table.IsEmpty could work for you....

Thanks! This worked pretty well.... the only issue Table.IsEmpty() gets me close but because the merged table column is returning multiple results due to the fact that other agents can and do call the same number.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.