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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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. 

 

jamesadsule_0-1658154956839.png

Appreciate your help

1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

1. First group by column [Order Num].

 

vkkfmsft_0-1658384732202.png

 

2. Then add a custom column.

 

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

vkkfmsft_1-1658384754430.png

 

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

 

vkkfmsft_2-1658384789537.png

 

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.

 

View solution in original post

3 REPLIES 3
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

1. First group by column [Order Num].

 

vkkfmsft_0-1658384732202.png

 

2. Then add a custom column.

 

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

vkkfmsft_1-1658384754430.png

 

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

 

vkkfmsft_2-1658384789537.png

 

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.

 

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. 

Greg_Deckler
Super User
Super User

@Anonymous Is there more to the logic? Because your data does not seem to reflect your wording that if B4 is equal to B3 then 1 else 0. Did you mean the reverse? While not Power Query, I have a repeating counter DAX measure/column that can do this sort of thing. https://community.powerbi.com/t5/Quick-Measures-Gallery/Cthulhu/m-p/509739#M211


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors