Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

help with text search with a deliminter

I tring to achieve the below, look for a value within a string and count the ID if the condition is met.

The 1st table is a summarised view of the data and the 2nd table is the desired outcome.

 

I've tried the below, but it is returning 106 for "Other", when it should be 131.

 

Program External Count = 
SWITCH(
    TRUE(),   
    CONTAINSSTRING('External Requets'[Program],"Other"),'External Requets'[COUNT],

    BLANK()
)

 

 

Data set: External Requets
Text Field: Program

Numerical Field : ID (a count of this not sum) 

or

COUNT : CALCULATE(COUNTA('External Requets'[ID]),NOT( ISBLANK('External Requets'[ID]))) 

 

 

Summarised data

 

ProgramCount
All LBM29
All LBM;#Other4
CCC Support11
CCC Support;#MMMcare;#All LBM3
CCC Support;#MMMcare;#All LBM;#Other2
CCC Support;#MMMcare;#Other1
DDD, SSSS and CCC3
DDD, SSSS and CCC;#EEEEE Services1
EEEG Information Line23
EEEG Information Line;#All LBM1
EEEEE Services7
FFF and Mummmm10
FFF and Mummmm;#Other1
FFF and Mummmm;#YYY and STUUU;#EEEEE Services1
MMMcare80
MMMcare;#All LBM;#Other1
MMMcare;#Other7
MMMcare;#PGTU Integrity;#All LBM1
OOO ZZZs15
OOO ZZZs;#DDD, SSSS and CCC;#Other1
OOO ZZZs;#FFF and Mummmm;#DDD, SSSS and CCC;#YYY and STUUU;#EEEEE Services10
OOO ZZZs;#FFF and Mummmm;#DDD, SSSS and CCC;#YYY and STUUU;#Other1
OOO ZZZs;#Other4
Other106
PGTU Integrity4
YYY and STUUU2
YYY and STUUU;#EEEEE Services2
OOO ZZZs;#DDD, SSSS and CCC;#EEEEE Services2
OOO ZZZs;#FFF and Mummmm;#DDD, SSSS and CCC;#YYY and STUUU;#EEEEE Services;#Other1
CCC Support;#MMMcare;#OOO ZZZs;#FFF and Mummmm;#DDD, SSSS and CCC;#YYY and STUUU;#EEEEE Services;#Other1
YYY and STUUU;#EEEEE Services;#Other1
FFF and Mummmm;#EEEEE Services1
FFF and Mummmm;#YYY and STUUU1
PGTU Integrity;#All LBM1
OOO ZZZs;#YYY and STUUU1

 

Desired result

 

ProgramID
CCC Support18
MMMcare96
PGTU Integrity6
OOO ZZZs36
FFF and Mummmm27
DDD, SSSS and CCC20
YYY and STUUU21
EEEEE Services27
All LBM42
Other131
EEEG Information Line24
  • Hi,

    In the Query Editor, split the contents into rows using ; as the delimiter.  Write this measure

    Measure = sum(Data[Count])

    Hope this helps.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,
    The helpful suggestions from Ashish_Mathur  and amitchandak can provide you with many ideas. I have created an example for you to solve the problem.
    1. Separate Program with ;# in Power Query

     

    2.Unpivot Column from Program.1 to Program.8

     

    Advanced Editor:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tVNdT8IwFP0rzfq6h22oaPqEmyMmNDMZe9gIDwtWXQIbqcXEf29XpaOlpRLCfeu5536ck97Fwpus12D2iD3fix68pS8BBDP2QSjHbwQcxzHId9ttRxnHwlAHEcQYr2pKEBxajtysYU50grzn/I5NksQHOQ9Qt6+AV8hRRxkEn/oAOaFfzYp8yh4cnILn9q2jm5o1XQtmTUv6LUb29KE02UVtPhZwmqZiAbzb8OjZgQHXZenZsizFO58XRWEV8ucRf98Hh4DB4VDN7+GxCr9M5wWXzsg7bdj3seYsy0BVVWKDWwVB0OC/Onyg6moNpU4Dgot72rZTP79kBXfirVokaUpv+aNdKiK3h86aS83UjbBc4dXmnUXWh1sO4+Q5SdZ/f7uxfvkD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Program = _t, Count = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Program", type text}, {"Count", Int64.Type}}),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Program", Splitter.SplitTextByDelimiter(";#", QuoteStyle.Csv), {"Program.1", "Program.2", "Program.3", "Program.4", "Program.5", "Program.6", "Program.7", "Program.8"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Program.1", type text}, {"Program.2", type text}, {"Program.3", type text}, {"Program.4", type text}, {"Program.5", type text}, {"Program.6", type text}, {"Program.7", type text}, {"Program.8", type text}}),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Count"}, "Attribute", "Value"),
        #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Value", "Count"}),
        #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Value", "Program"}})
    in
        #"Renamed Columns"

     

    Fianl output:

    How to Get Your Question Answered Quickly - Microsoft Fabric Community

    If it does not help, please provide more details with your desired out put and pbix file without privacy information.

     

    Best Regards,

    Ada Wang

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

     

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,
    The helpful suggestions from Ashish_Mathur  and amitchandak can provide you with many ideas. I have created an example for you to solve the problem.
    1. Separate Program with ;# in Power Query

     

    2.Unpivot Column from Program.1 to Program.8

     

    Advanced Editor:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tVNdT8IwFP0rzfq6h22oaPqEmyMmNDMZe9gIDwtWXQIbqcXEf29XpaOlpRLCfeu5536ck97Fwpus12D2iD3fix68pS8BBDP2QSjHbwQcxzHId9ttRxnHwlAHEcQYr2pKEBxajtysYU50grzn/I5NksQHOQ9Qt6+AV8hRRxkEn/oAOaFfzYp8yh4cnILn9q2jm5o1XQtmTUv6LUb29KE02UVtPhZwmqZiAbzb8OjZgQHXZenZsizFO58XRWEV8ucRf98Hh4DB4VDN7+GxCr9M5wWXzsg7bdj3seYsy0BVVWKDWwVB0OC/Onyg6moNpU4Dgot72rZTP79kBXfirVokaUpv+aNdKiK3h86aS83UjbBc4dXmnUXWh1sO4+Q5SdZ/f7uxfvkD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Program = _t, Count = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Program", type text}, {"Count", Int64.Type}}),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Program", Splitter.SplitTextByDelimiter(";#", QuoteStyle.Csv), {"Program.1", "Program.2", "Program.3", "Program.4", "Program.5", "Program.6", "Program.7", "Program.8"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Program.1", type text}, {"Program.2", type text}, {"Program.3", type text}, {"Program.4", type text}, {"Program.5", type text}, {"Program.6", type text}, {"Program.7", type text}, {"Program.8", type text}}),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Count"}, "Attribute", "Value"),
        #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Value", "Count"}),
        #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Value", "Program"}})
    in
        #"Renamed Columns"

     

    Fianl output:

    How to Get Your Question Answered Quickly - Microsoft Fabric Community

    If it does not help, please provide more details with your desired out put and pbix file without privacy information.

     

    Best Regards,

    Ada Wang

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

     

  • Hi,

    In the Query Editor, split the contents into rows using ; as the delimiter.  Write this measure

    Measure = sum(Data[Count])

    Hope this helps.