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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Mederic
Helper V
Helper V

If true then else

Hello everybody,
I'm stuck on a problem that looks easy but I can't find it.
I'm posting a screenshot with the explanations
Thank you in advance

Best regards

AB
20
22
10
02
00
11
21
30
00
14

 

1_2_3.png

1 ACCEPTED SOLUTION

Hi @Mederic,

 

You can use @lbendlin's solution and create a record that can be expanded, to illustrate:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTJQitWBsIzALEO4mAFczAAuBpI1hOuAsIxRdCDUmSjFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Result", each 
        [Both = null, Not Both = null, Clean = null] &
        (
            if [A]>0 and [B]>0 then [Both = 1] else 
            if [A]=0 and [B]=0 then [Clean = 3] else 
            [Not Both = 2]
        ), type [Both = Int64.Type, Not Both = Int64.Type, Clean = Int64.Type]
)
in
    #"Added Custom"

 

once expanded, it will yield this result

m_dekorte_0-1734860297426.png

 

 

 

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

wrong order of checks.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTJQitWBsIzALEO4mAFczAAuBpI1hOuAsIxRdCDUmSjFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Result", each 

if [A]>0 and [B]>0 then 1 else 
if [A]=0 and [B]=0 then 3 else 
2
)
in
    #"Added Custom"

 

Hello @lbendlin 
Thank you for your reply,
Your result is in a single column whereas I wanted it in 3 additional columns.

Best regards

Hi @Mederic,

 

You can use @lbendlin's solution and create a record that can be expanded, to illustrate:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTJQitWBsIzALEO4mAFczAAuBpI1hOuAsIxRdCDUmSjFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Result", each 
        [Both = null, Not Both = null, Clean = null] &
        (
            if [A]>0 and [B]>0 then [Both = 1] else 
            if [A]=0 and [B]=0 then [Clean = 3] else 
            [Not Both = 2]
        ), type [Both = Int64.Type, Not Both = Int64.Type, Clean = Int64.Type]
)
in
    #"Added Custom"

 

once expanded, it will yield this result

m_dekorte_0-1734860297426.png

 

 

 

Hello @m_dekorte 

Super, thank you very much, it works very well

Best regards

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.