Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Greetings,
Here is a sample of my data:
ID | SignedBy | Price |
ABC123 | Alondra | $2,500 |
ABC123 | Peter | $2,500 |
ABC123 | Roman | $2,500 |
ZXCV4657 | Steven | $100 |
HJKL4321 | John | $100 |
HJKL4321 | Alexa | $100 |
KMEF8293 | Mildred | $47,890 |
KMEF8293 | Maria | $47,890 |
Expected results:
ID | SignedBy | Price | Status |
ABC123 | Alondra | $2,500 | Passed |
ABC123 | Peter | $2,500 | Passed |
ABC123 | Roman | $2,500 | Passed |
ZXCV4657 | Steven | $100 | N/A |
HJKL4321 | John | $500 | N/A |
HJKL4321 | Alexa | $500 | N/A |
KMEF8293 | Mildred | $47,890 | Failed |
KMEF8293 | Maria | $47,890 | Failed |
Compliance rules:
General idea:
I have attempted adding a custom column to the main table in Power BI using IF, Countrows, Filter and Earlier, but I have had no luck. If the solution can be built in Power Query, better; but I am open to all your great solutions. Thanks!!! 😁
Solved! Go to Solution.
Give this code a try:
let
Source = Table,
GR1 = Table.Group(
Source,
{"ID"},
{
{"count", each Table.RowCount(_), Int64.Type},
{"all", each _, type table [ID = nullable text, SignedBy = nullable text, Price = nullable number]},
{"max", each List.Max([Price]), type nullable number}
}
),
AllSignedBy = Table.AggregateTableColumn(GR1, "all", {{"SignedBy", Text.Combine, "SignedBy"}}),
AddStatus = Table.AddColumn(
AllSignedBy,
"Status",
each
if [max] >= 2000 and Text.Contains(Text.Lower([SignedBy]), "peter") then
"Passed"
else if [max] < 2000 then
"N/A"
else
"Failed",
type text
),
ROC1 = Table.SelectColumns(AddStatus, {"ID", "Status"}),
Merge1 = Table.NestedJoin(ROC1, {"ID"}, Source, {"ID"}, "Removed Other Columns", JoinKind.LeftOuter),
Expand1 = Table.ExpandTableColumn(Merge1, "Removed Other Columns", {"SignedBy", "Price"}, {"SignedBy", "Price"})
in
Expand1
Table = The source table you provided above.
It's a little crude and can be improved upon but it should help get you what you're looking for.
Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
If you found this post helpful, please give Kudos. It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen. If you find my signature vaguely amusing, please give Kudos. | Proud to be a Super User! |
Give this code a try:
let
Source = Table,
GR1 = Table.Group(
Source,
{"ID"},
{
{"count", each Table.RowCount(_), Int64.Type},
{"all", each _, type table [ID = nullable text, SignedBy = nullable text, Price = nullable number]},
{"max", each List.Max([Price]), type nullable number}
}
),
AllSignedBy = Table.AggregateTableColumn(GR1, "all", {{"SignedBy", Text.Combine, "SignedBy"}}),
AddStatus = Table.AddColumn(
AllSignedBy,
"Status",
each
if [max] >= 2000 and Text.Contains(Text.Lower([SignedBy]), "peter") then
"Passed"
else if [max] < 2000 then
"N/A"
else
"Failed",
type text
),
ROC1 = Table.SelectColumns(AddStatus, {"ID", "Status"}),
Merge1 = Table.NestedJoin(ROC1, {"ID"}, Source, {"ID"}, "Removed Other Columns", JoinKind.LeftOuter),
Expand1 = Table.ExpandTableColumn(Merge1, "Removed Other Columns", {"SignedBy", "Price"}, {"SignedBy", "Price"})
in
Expand1
Table = The source table you provided above.
It's a little crude and can be improved upon but it should help get you what you're looking for.
Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
If you found this post helpful, please give Kudos. It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen. If you find my signature vaguely amusing, please give Kudos. | Proud to be a Super User! |
Hello. Thanks for the input. It almost worked out of the box! The single modification that I had to do, after an hour or so of looking for what may be wrong and trying tons of stuff, was removing the Text.Lower portion of the AddStatus step. It works great. Now, I am modifying stuff a little bit to just add the Status column to existing main table, which has over 30 more columns. Thanks for your help!!!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
143 | |
85 | |
65 | |
51 | |
45 |
User | Count |
---|---|
218 | |
88 | |
83 | |
65 | |
56 |