cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PoweBI Member
Member

Group based on condition

Hello Communities,

I am not sure how to group below into power bi power query?

I am trying to group multiple column based on the condition,

I want to group id column if rows numbers are same (Example:20657) and group Answer column by “Y” and “N” and group Area column if both rows are same (Example Americas).

Id

Answer

Area

20657

Y

Americas

20657

N

Americas

20933

N

Americas

20348

Y

Americas

 

 

 

 

 

Expecte Result

Id

Answer

Area

Result

20657

Y

Americas

2

20657

N

Americas

2

20933

N

Americas

1

20348

Y

Americas

1

 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User IV
Super User IV

Re: Group based on condition

@PoweBI hope attached will help, you can group by id and also put allrows in group and then expand it.






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: Group based on condition

@PoweBI,

 

You may try to add a custom column.

let
    r = _
in
    Table.RowCount(Table.SelectRows(Source, each [Id] = r[Id] and [Area] = r[Area]))
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PoweBI Member
Member

Re: Group based on condition

Hi Sam,

Please see below i am getting below error,From error i can say it is sheet and table error but i am not sure how dealt with this error?

let
    Source = Excel.Workbook(File.Contents("C:\Users\deletemondya.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Id", Int64.Type}, {"Answer", type text}, {"Area", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let
    r=_
in 
  Table.RowCount(Table.SelectRows(Source,each[Id]=r[Id]
  and [Area]=r[Area]))),
    Custom = #"Added Custom"{0}[Custom]
in
    Custom

commnity.png

Super User IV
Super User IV

Re: Group based on condition

@PoweBI hope attached will help, you can group by id and also put allrows in group and then expand it.






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





View solution in original post

PoweBI Member
Member

Re: Group based on condition

Thank you so much Parry.It is working perfectly fine.

Helpful resources

Announcements
Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors