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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ruthgammack
Frequent Visitor

switch statement using text and a number column

Trying the below when the kms are 0 it still will return a 0 and not 20. Is there a way i can use the below with some minor changes??
 
Buffer Kms = SWITCH(TRUE(),
('Co-ordinate'[Mode] = "Air") , 'Co-ordinate'[Kms]/100*22,
('Co-ordinate'[Mode] = "Sea") ,'Co-ordinate'[Kms]/100*24,
('Co-ordinate'[Mode] = "Roa"), 'Co-ordinate'[Kms]/100*18,
('Co-ordinate'[Mode] = "Rai"), 'Co-ordinate'[Kms]/100*9,
('Co-ordinate'[Mode] = "Cou"), 'Co-ordinate'[Kms]/100*22,
('Co-ordinate'[Kms] = 0), 20, 0
)
1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @ruthgammack 

Try this:

Buffer Kms =
IF (
    'Co-ordinate'[Kms] = 0,
    20,
    SWITCH (
        TRUE (),
        ( 'Co-ordinate'[Mode] = "Air" ),
            'Co-ordinate'[Kms] / 100 * 22,
        ( 'Co-ordinate'[Mode] = "Sea" ),
            'Co-ordinate'[Kms] / 100 * 24,
        ( 'Co-ordinate'[Mode] = "Roa" ),
            'Co-ordinate'[Kms] / 100 * 18,
        ( 'Co-ordinate'[Mode] = "Rai" ),
            'Co-ordinate'[Kms] / 100 * 9,
        ( 'Co-ordinate'[Mode] = "Cou" ),
            'Co-ordinate'[Kms] / 100 * 22
    )
)

 

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

Appreciate your Kudos✌️!!

View solution in original post

4 REPLIES 4

I have refering url column under which urls listed like below

google.com
facebook.com

instagram.com
linkedin.com

i want ad need column which lists respective urls

 

how can i do

VahidDM
Super User
Super User

Hi @ruthgammack 

Try this:

Buffer Kms =
IF (
    'Co-ordinate'[Kms] = 0,
    20,
    SWITCH (
        TRUE (),
        ( 'Co-ordinate'[Mode] = "Air" ),
            'Co-ordinate'[Kms] / 100 * 22,
        ( 'Co-ordinate'[Mode] = "Sea" ),
            'Co-ordinate'[Kms] / 100 * 24,
        ( 'Co-ordinate'[Mode] = "Roa" ),
            'Co-ordinate'[Kms] / 100 * 18,
        ( 'Co-ordinate'[Mode] = "Rai" ),
            'Co-ordinate'[Kms] / 100 * 9,
        ( 'Co-ordinate'[Mode] = "Cou" ),
            'Co-ordinate'[Kms] / 100 * 22
    )
)

 

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

Appreciate your Kudos✌️!!

unfortunately it doesnt work. ill keep trying

Anonymous
Not applicable

The last condition must be the first. It really does matter what you put where in switch.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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