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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Vemul
Helper I
Helper I

Replace Values Based on Condition n Power Query

Hi Team,

please help, 

 

what I am looking is based on belwo table,

if Client is 99638 and Type is "Sample" then Client value to be changed to 99999.

if Client is 99567 and Type is "Sample" then Client value no chnage.

Vemul_0-1714998705409.png

could oyu please provide me query to solve this

Thanks

VJ

 

2 ACCEPTED SOLUTIONS
slorin
Super User
Super User

Hi, @Vemul 

 

= Table.ReplaceValue(Your_Source, each [Type], 99999, (x,y,z)=> if x=99638 and y="Sample" then z else x, {"Client"})

Stéphane

View solution in original post

dufoq3
Super User
Super User

Hi @Vemul

 

Before

dufoq3_0-1715000173218.png

 

After

dufoq3_1-1715000183499.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsrQ0M7ZQ0lHyL8pMz8xLzFGK1QEJmpqZAwWDE3MLclKhQhB1KEIQVQitsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Client = _t, Type = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Client", Int64.Type}}),
    ReplacedClient = Table.ReplaceValue(ChangedType,
        each [Client] = 99638 and [Type] = "Sample",
        each 99999,
        (x,y,z)=> if y then z else x,
        {"Client"} )
in
    ReplacedClient

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

6 REPLIES 6
Vemul
Helper I
Helper I

Thank you, Solution worked as expected.
Vemul
Helper I
Helper I

Thank you, Solution worked as expected.
Vemul
Helper I
Helper I

Thank you, Solution worked as expected.
Vemul
Helper I
Helper I

Thanks you, Solution worked as expected.
dufoq3
Super User
Super User

Hi @Vemul

 

Before

dufoq3_0-1715000173218.png

 

After

dufoq3_1-1715000183499.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsrQ0M7ZQ0lHyL8pMz8xLzFGK1QEJmpqZAwWDE3MLclKhQhB1KEIQVQitsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Client = _t, Type = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Client", Int64.Type}}),
    ReplacedClient = Table.ReplaceValue(ChangedType,
        each [Client] = 99638 and [Type] = "Sample",
        each 99999,
        (x,y,z)=> if y then z else x,
        {"Client"} )
in
    ReplacedClient

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

slorin
Super User
Super User

Hi, @Vemul 

 

= Table.ReplaceValue(Your_Source, each [Type], 99999, (x,y,z)=> if x=99638 and y="Sample" then z else x, {"Client"})

Stéphane

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors