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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
JannePK
Regular Visitor

Summarize values over multiple columns

Hi,

 

can't get my head around the following problem:

 

I have a table of company data name, country etc including five "category" columns which may have data in zero to five of them, this category data coming from a finite set of values.

Company NameCountryService1Service2Service3Service4Service5
aUSAsalesconsultingHR  
bCANIPRsales   
cMEXconsultinglegalmarketingsalesIPR
dUSAHRIPRconsulting  
eCANmarketingsaleslegalIPR 
fUSAsales    
gUSAconsulting    

 

I would like to create a summary table out of this data showing the distribution of service category values over countries.

 salesconsultingHRIPRlegalmarketing
USA232100
CAN200211
MEX110111

 

What to do - thanks in advance 🙂

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@JannePK 

 

Following M works with your sample data

Please see the attached file's query editor for steps

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUQoNdgSSxYk5qcVAOjk/r7g0pyQzLx3I8QgCEgpgHKsTrZQEZDk7+gFJz4AgJD0KKKqSgSxf1wh0s3JS0xNzgHRuYlF2KlQMZgDIOJDWFLhzwDZDbEExBWFNKtwx2EyE2QYxAqIjDcOzChiOT4erwWItBCvFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Company Name" = _t, Country = _t, Service1 = _t, Service2 = _t, Service3 = _t, Service4 = _t, Service5 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Company Name", type text}, {"Country", type text}, {"Service1", type text}, {"Service2", type text}, {"Service3", type text}, {"Service4", type text}, {"Service5", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Company Name", "Country"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Value] <> "" and [Value] <> " ")),
    #"Duplicated Column" = Table.DuplicateColumn(#"Filtered Rows", "Country", "Country - Copy"),
    #"Removed Columns1" = Table.RemoveColumns(#"Duplicated Column",{"Company Name"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Value]), "Value", "Country - Copy", List.Count)
in
    #"Pivoted Column"

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@JannePK 

 

Following M works with your sample data

Please see the attached file's query editor for steps

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUQoNdgSSxYk5qcVAOjk/r7g0pyQzLx3I8QgCEgpgHKsTrZQEZDk7+gFJz4AgJD0KKKqSgSxf1wh0s3JS0xNzgHRuYlF2KlQMZgDIOJDWFLhzwDZDbEExBWFNKtwx2EyE2QYxAqIjDcOzChiOT4erwWItBCvFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Company Name" = _t, Country = _t, Service1 = _t, Service2 = _t, Service3 = _t, Service4 = _t, Service5 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Company Name", type text}, {"Country", type text}, {"Service1", type text}, {"Service2", type text}, {"Service3", type text}, {"Service4", type text}, {"Service5", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Company Name", "Country"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Value] <> "" and [Value] <> " ")),
    #"Duplicated Column" = Table.DuplicateColumn(#"Filtered Rows", "Country", "Country - Copy"),
    #"Removed Columns1" = Table.RemoveColumns(#"Duplicated Column",{"Company Name"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Value]), "Value", "Country - Copy", List.Count)
in
    #"Pivoted Column"

Thanks a lot - this worked exactly as expected!

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.