Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi all!
I've tried to find it before posting as a new topic but I couldn't find anything.
I'm trying to count how many "Y" I have on an specific range in the same row - which in excel I'd use =COUNTIFS(AI2:AL2,"Y") for the below:
Is there any way I can do it in Power Query (M) or as a DAX measure? I've managed to create the count for how many time "Y" appears in the entire row but not the specifc range (AI:AL).
Thanks,
Ana
Solved! Go to Solution.
In case anyone is interested, this is what I tried and it worked:
#"Added Count of Ys" = Table.AddColumn(#"Added Payment Type", "Count of Ys", each List.Count (List.Select({34,35,36,37}, each _ = "Y")))
Where: 34,35,36 and 37 are the column numbers in Power Query.
I've noticed that the created column is actually named as "count" only and comes right after column 37 instead - which I'm happy with that but just so you bear in mind in case it looks like it works but you don't see the column towards the end of your data as expected.
Thanks,
Ana
pls try this
List.Count(
List.Select(
Record.FieldValues(_),
each _ = "Y")
)
In case anyone is interested, this is what I tried and it worked:
#"Added Count of Ys" = Table.AddColumn(#"Added Payment Type", "Count of Ys", each List.Count (List.Select({34,35,36,37}, each _ = "Y")))
Where: 34,35,36 and 37 are the column numbers in Power Query.
I've noticed that the created column is actually named as "count" only and comes right after column 37 instead - which I'm happy with that but just so you bear in mind in case it looks like it works but you don't see the column towards the end of your data as expected.
Thanks,
Ana
Dear @AnaR Doesn't this work if you give reference of the actual column names instead of column numbers?
Because, when I have used below code, I'm getting 0 as result in all of the rows, I wonder what is the issue in this:
= Table.AddColumn(#"Changed Type", "TotalMinsPerWeek", each List.Count(List.Select({"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}, each _ = "Y")))
Hi Ahmedx,
Thanks for that. This is what I tried last week but it counts all "Y"s from my row - my data has more than those four columns so I need to specify which columns it needs to read from.
Thanks,
Ana
Hi,
you could try using this in a custom column:
let thisrecordlist = Record.ToList(_) in List.Count(List.Select(List.Transform({2,3}, each thisrecordlist{_}), each Text.Contains(_, "Y")))
you'll need to change the numbers of the columns you want to include in the section List.Transform({2,3} this list would pick up the equivilant of column B and C in excel.
If I answered your question, please mark my post as solution, Appreciate your Kudos 👍
Hello,
Thanks for that. That hasn't worked but I've tried something similar which it worked:
= Table.AddColumn(
#"Added Payment Type", "Count of Ys", each
List.Count (
List.Select({34,35,36,37}, each _ = "Y")))
Thanks,
Ana
User | Count |
---|---|
76 | |
75 | |
46 | |
31 | |
27 |
User | Count |
---|---|
99 | |
91 | |
51 | |
48 | |
47 |