Forum Discussion

Rico56's avatar
Rico56
New Member
6 years ago
Solved

Count value in columns

Hello,

 

I have something like this:

 

Clientcol1col2col2
c1OKOKOK
c2OKOKCRIT
c3WARNWARNOK
c4OKOKOK
c5OKCRITOK
c6WARNOKOK
c7OKOKOK
c8WARNOKWARN
c9OKOKOK

 

I try to make a calculated columns to have :

col1total
OK6
WARN3
CRIT0

 

col2total
OK7
WARN1
CRIT1

 

col3total
OK7
WARN1
CRIT1

 

I'm a beginner with Power BI.

Thanks in advance for your help.

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Unless you absolutely need it to be in a calculated column, you could drop col1/col2/col3 twice into the visual.

     

    If you choose a table visual, drop the same column in the Value-well twice. The first one will show the distinct values in the column, and for the second one you choose the drop-down button on the column name in the Values-well, and choose Count.

  • smpa01's avatar
    smpa01
    Community Champion

    Rico56  it can done tyhis way by using M

    let
        Source = Web.BrowserContents("https://community.powerbi.com/t5/Desktop/Count-value-in-columns/m-p/926208#M443898"),
        #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > TR > :nth-child(1), DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > * > TR > :nth-child(1)"}, {"Column2", "DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > TR > :nth-child(2), DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > * > TR > :nth-child(2)"}, {"Column3", "DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > TR > :nth-child(3), DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > * > TR > :nth-child(3)"}, {"Column4", "DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > TR > :nth-child(4), DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > * > TR > :nth-child(4)"}}, [RowSelector="DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > TR, DIV[id='bodyDisplay'] > DIV.lia-message-body-content:nth-child(1) > TABLE:nth-child(5) > * > TR"]),
        #"Changed Type" = Table.TransformColumnTypes(#"Extracted Table From Html",{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}}),
        #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Client", type text}, {"col1", type text}, {"col2", type text}, {"col2_1", type text}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"col2_1", "col3"}}),
        #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Client"}),
        Custom1 = Table.DemoteHeaders(#"Removed Columns"),
        #"Changed Type2" = Table.TransformColumnTypes(Custom1,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}}),
        #"Transposed Table" = Table.Transpose(#"Changed Type2"),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Transposed Table", {"Column1"}, "Attribute", "Value"),
        #"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
        #"Grouped Rows" = Table.Group(#"Removed Columns1", {"Column1", "Value"}, {{"Count", each Table.RowCount(_), type number}})
    in
        #"Grouped Rows"

     

  • Many thanks for all replies.

    Now it works. I have many things to learn about Power BI.