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

Join 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.

Reply
dekkerge
New Member

How can I add a custom column to Power BI query to label a product as the current version?

I am very new to Power BI but I am building a dashboard of many different products throughout a few different stages of their development which we call "Gates." I'm doing this partly as a learning opportunity so I'm trying to figure out how I can add a column to designate one version of each product as the "Current" version. I want to keep the previous versions in the query as well in order to compare how the products have developed over time.

 

Below is an example of what the data looks like in the query:

 

dekkerge_0-1731618663981.png

 

There are a bunch of products, all at different stages of development. I upload a new file to a folder for each product at each gate. I want to add a column to the data set that looks through the Product and Gate columns in the query and labels the most recent version of each product as "Current." So in my example, Prouct 1 is current at gate D, Product 2 is Current at Gate B, Product 3 at C and Product 4 at D. Is there an elegant way to do this in the Query by adding a custom column?

2 ACCEPTED SOLUTIONS
PwerQueryKees
Super User
Super User

 

 

Table.AddColumn(Source, "IsCurrent",
   each [Gate] = List.Max(Table.SelectRows(Source, each (S) => S[Product] = [Product])[Gate]))
   ) 

 

Not tested, so minor errors may exist....

 

View solution in original post

Anonymous
Not applicable

Hi,

Thanks for the solution PwerQueryKees offered, and i want to offer some more information for user to refer to.

hello @dekkerge , you can use group by in power query.

You can refer to the following code in advanced editor in power query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKTylNLlEwVNJRcgRiQ0MDA6VYHVQJJ5CEgSmmhDNYwtAUQ8IFiC3NUDUYwawwMcCUAFthjCZhDNNhikXCCZtRxjBHmaFJmECNsjTFFId4zxxTAmSSpQWmONh3hkDxWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Gate = _t, Cost = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Gate", type text}, {"Cost", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"CurrentGate", each List.Max([Gate]), type nullable text}, {"Data", each _, type table [Product=nullable text, Gate=nullable text, Cost=nullable number]}}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Gate", "Cost"}, {"Gate", "Cost"})
in
    #"Expanded Data"

Output

vxinruzhumsft_0-1732071566855.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi,

Thanks for the solution PwerQueryKees offered, and i want to offer some more information for user to refer to.

hello @dekkerge , you can use group by in power query.

You can refer to the following code in advanced editor in power query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKTylNLlEwVNJRcgRiQ0MDA6VYHVQJJ5CEgSmmhDNYwtAUQ8IFiC3NUDUYwawwMcCUAFthjCZhDNNhikXCCZtRxjBHmaFJmECNsjTFFId4zxxTAmSSpQWmONh3hkDxWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, Gate = _t, Cost = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Gate", type text}, {"Cost", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"CurrentGate", each List.Max([Gate]), type nullable text}, {"Data", each _, type table [Product=nullable text, Gate=nullable text, Cost=nullable number]}}),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Gate", "Cost"}, {"Gate", "Cost"})
in
    #"Expanded Data"

Output

vxinruzhumsft_0-1732071566855.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Omid_Motamedise
Super User
Super User

Please provide your sample data as table here

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
PwerQueryKees
Super User
Super User

 

 

Table.AddColumn(Source, "IsCurrent",
   each [Gate] = List.Max(Table.SelectRows(Source, each (S) => S[Product] = [Product])[Gate]))
   ) 

 

Not tested, so minor errors may exist....

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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