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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Scott_S_is_me
New Member

Displaying Only Matching Rows But Needing Additional Columns Included

Hello all,

 

I'm needing a way to display only matching values in columns with additional columns needed for context.  For example:

 

DateNameExpense ItemLine Amount
Jan 1 2021Bob SmithCar Rental$100
Jan 1 2021Bob SmithMileage$30
Jan 2 2021Bob SmithCar Rental$100
Jan 3 2021Bob SmithCar Rental$100

 

I would like to see only rows that a person expensed car rental and mileage on the same day.  So in the example I would expect to see:

DateNameExpense ItemLine Amount
Jan 1 2021Bob SmithCar Rental$100
Jan 1 2021Bob SmithMileage$30

 

 

Any assistance would be greatly appreciated.

1 ACCEPTED SOLUTION
adudani
Super User
Super User

hi @Scott_S_is_me ,

 

Create a blank query. Copy and paste the following code below into it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMUzBUMDIwMlTSUXLKT1IIzs0syQCynROLFIJS80oSc4AcFUMDA6VYHTzKfTNzUhPTU0FqjRFKjUgz2ZhI5bEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, #"Expense Item" = _t, #"Line Amount" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Expense Item", type text}, {"Line Amount", Currency.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "Name"}, {{"Details", each _, type table [Date=nullable date, Name=nullable text, Expense Item=nullable text, Line Amount=nullable number]}}),
    CheckforValue = Table.AddColumn(#"Grouped Rows", "Custom", each if List.Contains([Details][Expense Item], "Car Rental") and List.Contains([Details][Expense Item], "Mileage") then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(CheckforValue, each ([Custom] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom", "Date", "Name"}),
    #"Expanded Details" = Table.ExpandTableColumn(#"Removed Columns", "Details", {"Date", "Name", "Expense Item", "Line Amount"}, {"Date", "Name", "Expense Item", "Line Amount"})
in
    #"Expanded Details"

 

Steps taken:

1. Grouped table by Name and Date, added a "Details" column summarizing all distinct rows.

2. Created a "Custom" Column, checking if the "Expense Item" in Detail for the grouped name and date contains the two values, if it does then 1 else 0. ( THIS IS CASE SENSITIVE).

3. Filter the Custom column for values with 1.

4. Removed all columns other than Details. Expanded the Details Column.

 

File: Expensecondition.pbix

 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

View solution in original post

2 REPLIES 2
adudani
Super User
Super User

hi @Scott_S_is_me ,

 

Create a blank query. Copy and paste the following code below into it.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8krMUzBUMDIwMlTSUXLKT1IIzs0syQCynROLFIJS80oSc4AcFUMDA6VYHTzKfTNzUhPTU0FqjRFKjUgz2ZhI5bEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, #"Expense Item" = _t, #"Line Amount" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Expense Item", type text}, {"Line Amount", Currency.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "Name"}, {{"Details", each _, type table [Date=nullable date, Name=nullable text, Expense Item=nullable text, Line Amount=nullable number]}}),
    CheckforValue = Table.AddColumn(#"Grouped Rows", "Custom", each if List.Contains([Details][Expense Item], "Car Rental") and List.Contains([Details][Expense Item], "Mileage") then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(CheckforValue, each ([Custom] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom", "Date", "Name"}),
    #"Expanded Details" = Table.ExpandTableColumn(#"Removed Columns", "Details", {"Date", "Name", "Expense Item", "Line Amount"}, {"Date", "Name", "Expense Item", "Line Amount"})
in
    #"Expanded Details"

 

Steps taken:

1. Grouped table by Name and Date, added a "Details" column summarizing all distinct rows.

2. Created a "Custom" Column, checking if the "Expense Item" in Detail for the grouped name and date contains the two values, if it does then 1 else 0. ( THIS IS CASE SENSITIVE).

3. Filter the Custom column for values with 1.

4. Removed all columns other than Details. Expanded the Details Column.

 

File: Expensecondition.pbix

 

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

Got it to work.  Thank you so much!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors