Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

How to Use If function at each row level

Hello BI Community,

 

I am newbie to Power BI and hence need your help in fixing one problem I am trying to automate with Power BI in huge excel file. 

Basically I want to derive value '0' and '1' using if function in Power BI starting from Row 2. Row one which is cell 'D3' in this case will always be 1 by default.  I have attached below screenshot where cell 'D3' represents first row which is '1' by defalut and from second row onwards if Order number in cell 'B5' is equal to 'B4', then it should give a value '0' or else '1'. 

This is going to be used in critical dashboard where i want to sum each unique Order Number with specific other filters. 

 

Appreciate your help

  • Hi Anonymous ,

     

    1. First group by column [Order Num].

     

     

    2. Then add a custom column.

     

    = Table.AddColumn(Table.AddIndexColumn([ALL], "Index", 1), "Count Rows", each if [Index] = 1 then 1 else 0)

     

    3. Delete the other columns and keep only the Custom column, and extend it.

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    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

    Greg_Deckler - No it is not reverse, I just reworded my question again.  I want to reflect row as '1' if it is not duplicate of subsequent row except for 'D3' cell which has to be '1' by default. 

    I have sorted 'Order number' column from A to Z in order to reflect correct 0 and 1. 

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi Anonymous ,

     

    1. First group by column [Order Num].

     

     

    2. Then add a custom column.

     

    = Table.AddColumn(Table.AddIndexColumn([ALL], "Index", 1), "Count Rows", each if [Index] = 1 then 1 else 0)

     

    3. Delete the other columns and keep only the Custom column, and extend it.

     

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.