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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JBDelvaux
Helper I
Helper I

Replace "0" value with another one if available

Greetings, I have a table as such. These informations are received to the database but from different devices that do not have access ot the same informations. As a result, one of the device cannot accurately tell which user did the job, leaving it to a UserId of 0.

JBDelvaux_0-1704200912116.png

I would like, if a line with a userID value is at "0" to check if another line with the same "Piece" number exist with a value different than 0 and to replace said 0 with the UserID found. If no other number is found, to keep it at 0.

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

You can try something like this. Note I'm using a simple example.

Do "Group By" on the Piece column, Choose "All Rows" and transform the result, like so.

 

let
  Source = Table.FromColumns(
    {
      {"A" .. "H"}, 
      {123 .. 127, 0, 0, 128}, 
      {546038 .. 546042, 546042, 546042, 546043}
    }, 
      {"Column1", "UserId", "Piece"}
  ), 
  GroupRows = Table.Group(
    Source, 
    {"Piece"}, 
    {{"t", each Table.TransformColumns(_, {"UserId", (x) => List.Max(_[UserId])})}}
  ), 
  ExpandAll = Table.Combine(GroupRows[t])
in
  ExpandAll

 

I hope this is helpful

View solution in original post

1 REPLY 1
m_dekorte
Super User
Super User

You can try something like this. Note I'm using a simple example.

Do "Group By" on the Piece column, Choose "All Rows" and transform the result, like so.

 

let
  Source = Table.FromColumns(
    {
      {"A" .. "H"}, 
      {123 .. 127, 0, 0, 128}, 
      {546038 .. 546042, 546042, 546042, 546043}
    }, 
      {"Column1", "UserId", "Piece"}
  ), 
  GroupRows = Table.Group(
    Source, 
    {"Piece"}, 
    {{"t", each Table.TransformColumns(_, {"UserId", (x) => List.Max(_[UserId])})}}
  ), 
  ExpandAll = Table.Combine(GroupRows[t])
in
  ExpandAll

 

I hope this is helpful

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors