Forum Discussion

prashantg364's avatar
prashantg364
Helper II
3 years ago
Solved

Power query or DAX

Hi all,

 

I have a data set as shown in the input table,

Against each product name & product band, I have 2 KPI categories, 1. 3 KPI and 2. 5 KPI. In columns 3 & 4 I have total pass KPIs in each category. In the following few columns I have the details for failed KPIs in terms of 1 & 0. 1 means KPI is pass & 0 means KPI is fail.

 

Now I want to summarize my table where I can have only one row for each Product name & Product band combination, followed by pass KPI count in the next 2 columns for 2 different categories, and in the next 2 columns I want the failed KPI names separated by commas, as shown in output table.

 

Pls help, how I can do this either through power Query editor or by using some DAX.

 

Input table

Product nameProduct bandKPI Category - 3 KPI(KPI1,KPI2,KPI3)KPI Category - 5 KPI(KPI1,KPI2,KPI3,KPI4,KPI5)KPI1KPI2KPI3KPI4KPI5
Car73511111
Car31210001
Bike72211000
Bike33311100
Cycle73411110
Cycle30000000

 

Output table

 

Product nameProduct bandTotal pass in 3 KPITotal pass in 5 KPIFailed KPI -KPI Category - 3 KPI(KPI1,KPI2,KPI3)Failed KPI - KPI Category - 5 KPI(KPI1,KPI2,KPI3,KPI4,KPI5)
Car735  
Car312KPI2,KPI3KPI2, KPI3, KPI4
Bike722KPI3KPI3, KPI4, KPI5
Bike333 KPI4, KPI5
Cycle734 KPI5
Cycle300KPI1,KPI2,KPI3KPI1,KPI2,KPI3,KPI4,KPI5
  • Hi

    Add new columns

    =Text.Combine(List.Transform({{[KPI1],"KPI1"},{[KPI2],"KPI2"},{[KPI3],"KPI3"}}, each if _{0}=0 then _{1} else null), ",")

    and

    Text.Combine(List.Transform({{[KPI1],"KPI1"},{[KPI2],"KPI2"},{[KPI3],"KPI3"},{[KPI4],"KPI4"},{[KPI5],"KPI5"}}, each if _{0}=0 then _{1} else null), ",") 

    Stéphane 

4 Replies

  • Hello, prashantg364 

    let
        Source = your_table,
        lst03 = {"KPI1", "KPI2", "KPI3"},
        lst05 = {"KPI1", "KPI2", "KPI3", "KPI4", "KPI5"},
        f = (r as record, lst as list) =>
            List.Accumulate(
                lst,
                {},
                (s, c) => s & (if Record.Field(r, c) = 0 then {c} else {})
            ),
        comb = Table.CombineColumnsToRecord(Source, "KPI", lst05),
        txf = Table.TransformColumns(comb, {"KPI", (x) => f(x, lst05)}),
        failed3 = 
            Table.AddColumn(
                txf, "Failed KPI -KPI Category - 3 KPI(KPI1,KPI2,KPI3)", 
                (x) => Text.Combine(List.Select(x[KPI], (w) => List.Contains(lst03, w)), ", ")
            ),
        failed5 = Table.AddColumn(failed3, "Failed KPI - KPI Category - 5 KPI(KPI1,KPI2,KPI3,KPI4,KPI5)", each Text.Combine([KPI], ", ")),
        remove_kpi = Table.RemoveColumns(failed5,{"KPI"})
    in
        remove_kpi
  • Hi

    Add new columns

    =Text.Combine(List.Transform({{[KPI1],"KPI1"},{[KPI2],"KPI2"},{[KPI3],"KPI3"}}, each if _{0}=0 then _{1} else null), ",")

    and

    Text.Combine(List.Transform({{[KPI1],"KPI1"},{[KPI2],"KPI2"},{[KPI3],"KPI3"},{[KPI4],"KPI4"},{[KPI5],"KPI5"}}, each if _{0}=0 then _{1} else null), ",") 

    Stéphane 

  • Punithurs's avatar
    Punithurs
    Frequent Visitor

    Hi prashantg364,
    If you want to achieve this with the simple calculated column using dax. 

    Step 1: 
    Concatenate the columns.

    Fail 3 = CONCATENATE(Sheet1[KPI1],CONCATENATE(Sheet1[KPI2],Sheet1[KPI3]))
    And,
    Text 3 = IF(Sheet1[Fail 3] = "111","",
    IF(Sheet1[Fail 3] = "110","KPI3",
    IF(Sheet1[Fail 3] = "100","KPI2,KPI3",
    IF(Sheet1[Fail 3] = "001","KPI1,KPI2",
    IF(Sheet1[Fail 3] = "010","KPI1,KPI3",
    IF(Sheet1[Fail 3] = "011","KPI1",
    "KPI1,KPI2,KPI3"))))))

     


     



    We can use the same technique for other column as well