cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Conditonal Column based on Calculated Columns

Hi, 

 

I have a table, where I have created 3 calculated columns, that tell me if that ID appears in another table. Looks like this: 

 

lyaneb_0-1595521873937.png

What I want to do is add another column that would categorise the rows and give them letters based on the other columns.

For example: 

If archivingvehicles = 1 and deleting vehicles = 0 and invoicingvehicles = 0 then "A", 

If archivingvehicles = 1 and deleting vehicles = 1 and invoicingvehicles = 0 then "A,D",

If archivingvehicles = 1 and deleting vehicles = 1 and invoicingvehicles = 1 then "A,D,I", 

If archivingvehicles = 0 and deleting vehicles = 1 and invoicingvehicles = 0 then "D", 

And so on. 

I would do this as a CASE WHEN in SQL but not sure in DAX.

 

Are you able to help on this, as it cannot be done in Power Query because the calculated columns do not show up. 


Thank you 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User V
Super User V

Re: Conditonal Column based on Calculated Columns

Hi @lyaneb ,

 

i missed an &

 

Try this

 

 

Calculated Column =
VAR a = 'Table'[archivingvehicles]
VAR b = 'Table'[deleting vehicles]
VAR c = 'Table'[invoicingvehicles]
RETURN
    SWITCH (
        TRUE (),
        a = 1
            && b = 0
            && c = 0, "A",
        a = 1
            && b = 1
            && c = 0, "A,D",
        a = 1
            && b = 1
            && c = 1, "A,D,I",
        a = 0
            && b = 1
            && c = 0, "D"
    )

 

 

Regards,

Harsh Nathani

 

 

View solution in original post

8 REPLIES 8
Highlighted
Resolver IV
Resolver IV

Re: Conditonal Column based on Calculated Columns

Hi,

 

You can use the "SWITCH" function in PowerBI. Declare variables like archivingvehicles = sum(archivingvehicles) and use them in switch function.

 

Appreciate a Kudos! 🙂
If this helps and resolves the issue, please mark it as a Solution! 🙂

Regards,
N V Durga Prasad

 

Highlighted
Super User V
Super User V

Re: Conditonal Column based on Calculated Columns

HI @lyaneb ,

 

 

Create a Calculated Column

 

Calculated Column =
VAR a = 'Table'[archivingvehicles]
VAR b = 'Table'[deleting vehicles]
VAR c = 'Table'[invoicingvehicles]
RETURN
    SWITCH (
        TRUE (),
        a = 1
            && b = 0 & c = 0, "A",
        a = 1
            && b = 1 & c = 0, "A,D",
        a = 1
            && b = 1 & c = 0, "A,D,I",
        a = 0
            && b = 1 & c = 0, "D"
    )

 

Regards,
Harsh Nathani

Appreciate with a Kudos!! (Click the Thumbs Up Button)
Did I answer your question? Mark my post as a solution!

Highlighted
Frequent Visitor

Re: Conditonal Column based on Calculated Columns

@harshnathani Thank you. 

 

I have tried it and I get this error. Are you able to help, I have not used this function before. 

 

"DAX comparison operations do not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values."

 

The three columns were a Data Type of 'Number', I tried changing them to Text but that hasn't resolved it. 

 

Thank you for your help

Highlighted
Super User V
Super User V

Re: Conditonal Column based on Calculated Columns

Hi @lyaneb ,

 

i missed an &

 

Try this

 

 

Calculated Column =
VAR a = 'Table'[archivingvehicles]
VAR b = 'Table'[deleting vehicles]
VAR c = 'Table'[invoicingvehicles]
RETURN
    SWITCH (
        TRUE (),
        a = 1
            && b = 0
            && c = 0, "A",
        a = 1
            && b = 1
            && c = 0, "A,D",
        a = 1
            && b = 1
            && c = 1, "A,D,I",
        a = 0
            && b = 1
            && c = 0, "D"
    )

 

 

Regards,

Harsh Nathani

 

 

View solution in original post

Highlighted
Frequent Visitor

Re: Conditonal Column based on Calculated Columns

Hi @harshnathani 

 

Afraid I am still getting the same error

 

 

Highlighted
Super User V
Super User V

Re: Conditonal Column based on Calculated Columns

Hi @lyaneb ,

 

 

Not sure why. I tried it. It is working.  make sure both places you have a &&    &&

 

1.jpg2.JPG3.JPG

 

 

Regards,

HN

Highlighted
Frequent Visitor

Re: Conditonal Column based on Calculated Columns

HI @harshnathani 

 

I'm not sure why either. What I have done is changed the 1,0 to YES and NO as a Text type and it has worked. 

 

Thank you for all your help!

Highlighted
Super User V
Super User V

Re: Conditonal Column based on Calculated Columns

Hi @lyaneb ,

 

The Column may have changed to Boolean or Text.

 

Change it to Whole Number or Decimal and this formula will work.

 

Regards,
Harsh Nathani

Appreciate with a Kudos!! (Click the Thumbs Up Button)
Did I answer your question? Mark my post as a solution!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Upcoming Events

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors