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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Adding Column that Assigns fixed value based on another colu

Hello, 

 

I am inquiring on how to add a column in Power Query (within Power BI), that will assign each row of data to the "Mattress" sold for that "Order". 

 

zdewolfe_0-1631120842904.png

 

See Below on what I want: (fake data used for illustration)

zdewolfe_1-1631120949471.png

 

This will allow me to use CALCULATE(SUM() to capture the average selling price of an Order, based on the Mattress sold within it. 

 

I feel like this is easy, yet I don't know how to do it. I am hooked up using Direct Query to Azure, into our data warehouse.

 

I know Direct Query comes with some limitations. I tried duplicating the table, and filtering down to ONLY mattresses, and then doing a query merge between the original and the new to pull in the Mattress sold within each order. But I don't know if this is working and I feel there has to be a better way. 

 

Thank you!

 

 

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Have you tried the merge queries method? Does it work?

 

Additionally, you can add a custom column with below code without a second table. 

Table.SelectRows(previousStep, (x)=> x[Order]=[Order] and x[Product]="Mattress"){0}[Product Type]

21091302.jpg

 

One concern is that you are using Direct Query, so this method may not be supported in Direct Query mode. If so, you will have to convert it to Import mode. 

 

As you said "This will allow me to use CALCULATE(SUM() to capture the average selling price of an Order, based on the Mattress sold within it. " Can you provide the expected output of the calculation so that we can think of DAX expressions supported in DirectQuery mode to calculate the result directly?

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

jennratten
Super User
Super User

Hello - there are a few different ways of accomplishing this. Here are a couple of options:

 

Option #1

Create a reference query with distinct rows for only the order number and mattress type columns, then merge with the primary query.

 

OrderDetails

jennratten_0-1631127849390.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyNjQyVtJR8k0sKSlKLS4GMiNAfGMDAwOlWB0kFU6JxalAyjElq7S4JDEpB8QxMkVT5FZalJdZUloEkvSIKTUwMDJzA5mGri4gMycnvxxkmzNI3txUKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order = _t, Product = _t, #"Product Type" = _t, #"Selling Price" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order", type text}, {"Product", type text}, {"Product Type", type text}, {"Selling Price", Int64.Type}})
in
    #"Changed Type"

OrderMattressTypes

jennratten_1-1631127977470.png

let
    Source = OrderDetails,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Product] = "Mattress")),
    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Order", "Product Type"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns")
in
    #"Removed Duplicates"

 

OrderDetailsWithMattressType

jennratten_2-1631128095611.png

let
    Source = Table.NestedJoin(OrderDetails, {"Order"}, OrderMattressTypes, {"Order"}, "OrderMattressTypes", JoinKind.LeftOuter),
    #"Expanded OrderMattressTypes" = Table.ExpandTableColumn(Source, "OrderMattressTypes", {"Product Type"}, {"Mattress Type"})
in
    #"Expanded OrderMattressTypes"

 

Option #2

Create a mattress types dimension table, create a relationship between the tables in the data model. Use the dimension table to filter the measure.

 

Same OrderDetails table as listed in Option #1.

 

MattressTypes

jennratten_3-1631128331257.png

 

let
    Source = OrderDetails,
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Product", "Product Type"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each ([Product] = "Mattress")),
    #"Removed Duplicates" = Table.Distinct(#"Filtered Rows")
in
    #"Removed Duplicates"

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors