Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello All,
Please I need your help on this, I have a table that contains a column named Ref and another column named status I need to get all the rows when status='On', then I should take all records when status=OFF and Ref are not taken from the beginning while taking the "On" status.
Thank you all in advance.
Hi @toum ,
Try this:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjNT0lHyd3MDko5KsTrRSuYIASewgKERXMAZImAKF3BBUuEHJFyRFID4bmC+EZzvDuGbw/geCPlwR88QTz93IMtbKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ref = _t, Status = _t, Link = _t]),
groupRef = Table.Group(Source, {"Ref"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"data", each _, type table [Ref=nullable text, Status=nullable text, Link=nullable text]}}),
expandData = Table.ExpandTableColumn(groupRef, "data", {"Status", "Link"}, {"Status", "Link"}),
filterCriteria = Table.SelectRows(expandData, each ([Status] = "OFF" and [Count] = 1) or ([Status] = "ON"))
in
filterCriteria
Summary:
1) groupRef = group on the [Ref] column and create one Count aggregate and one All Rows aggregate column.
2) expandData = expand the nested [data] column back out to reinstate original columns.
3) filterCriteria = filter table using [Count] column as part of the criteria.
Example output:
Pete
Proud to be a Datanaut!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
12 | |
8 | |
8 | |
7 |
User | Count |
---|---|
15 | |
13 | |
8 | |
7 | |
6 |