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
Sathvik123
Helper V
Helper V

How to write if else in power Bi Dax

Hello All,

 

I have a tableau dashboard where I have parameter having values like US-Canada,APAC and Overall.

And I have department values like Central,Georgia,Hyd and Pune

 

My requirement is If I select region as US-Canada then I need to show only Central,Georgia

                               If I select region as APAC then I need to show only Hyd,Pune

                                If I select region as Overall then I need to show All 4.i.e, Central,Georgia,Hyd,Pune

 

Below is my logic in Tableau and I am not sure how to write in power BI as I am new.

Could some one help how to write

 

I created a table inside power BI for the parameter values and not sure how to write after that

 

CASE [Region]
when 'US-Canada' then
[Department] = 'Central' or
[Department]= 'Georgia'
when 'APAC' then
[Department] = 'Hyd' or
[Department]= 'Pune'

when 'Overall' then
[Department] = 'Central' or
[Department] = 'Georgia' or
[Department]= 'Hyd' or
[Department] = 'Pune'
END

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Sathvik123 ,

 

Please try to Create a new table for slicer:

For Slicer =
FILTER (
    CROSSJOIN (
        { "US-Canada", "APAC", "Overall" },
        SUMMARIZE ( 'Table', [Department] )
    ),
    SWITCH (
        [Value],
        "APAC",
            [Department] = "Hyd"
                || [Department] = "Pune",
        "US-Canada",
            [Department] = "Central"
                || [Department] = "Georgia",
        [Department] = "Hyd"
            || [Department] = "Pune"
            || [Department] = "Central"
            || [Department] = "Georgia"
    )
)

vjianbolimsft_1-1661840970318.png

 

Then manage the relationship between the tables:

vjianbolimsft_0-1661840948556.png

Then apply 'For Slicer'[Value] and 'For Slicer'[Department] to slicers

Final output:

vjianbolimsft_3-1661841218865.png

 

vjianbolimsft_2-1661841181303.png

 

Best Regards,

Jianbo Li

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

 

View solution in original post

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @Sathvik123 ,

 

Please try to Create a new table for slicer:

For Slicer =
FILTER (
    CROSSJOIN (
        { "US-Canada", "APAC", "Overall" },
        SUMMARIZE ( 'Table', [Department] )
    ),
    SWITCH (
        [Value],
        "APAC",
            [Department] = "Hyd"
                || [Department] = "Pune",
        "US-Canada",
            [Department] = "Central"
                || [Department] = "Georgia",
        [Department] = "Hyd"
            || [Department] = "Pune"
            || [Department] = "Central"
            || [Department] = "Georgia"
    )
)

vjianbolimsft_1-1661840970318.png

 

Then manage the relationship between the tables:

vjianbolimsft_0-1661840948556.png

Then apply 'For Slicer'[Value] and 'For Slicer'[Department] to slicers

Final output:

vjianbolimsft_3-1661841218865.png

 

vjianbolimsft_2-1661841181303.png

 

Best Regards,

Jianbo Li

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

 

v-jianboli-msft
Community Support
Community Support

Hi @Sathvik123 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1661837582172.png

Please try:

First create a new table for slicer

vjianbolimsft_1-1661837687861.png

Then apply it to slicer and turn on single select :

vjianbolimsft_2-1661837735869.png

vjianbolimsft_3-1661837777987.png

Create a measure and apply to the visual:

Flag = 
SWITCH (
    SELECTEDVALUE ( 'For Slicer'[Value] ),
    "APAC",
        IF (
            MAX ( 'Table'[Department] ) = "Hyd"
                || MAX ( 'Table'[Department] ) = "Pune",
            1,
            0
        ),
    "US-Canada",
        IF (
            MAX ( 'Table'[Department] ) = "Central"
                || MAX ( 'Table'[Department] ) = "Georgia",
            1,
            0
        ),
    1
)

Apply it to the filter:

vjianbolimsft_4-1661838537387.png

Final output:

vjianbolimsft_5-1661838607213.png

vjianbolimsft_6-1661838623068.png

Refer to : IF function (DAX) - DAX | Microsoft Docs

Best Regards,

Jianbo Li

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

 

 

 

 

 

 

 

 

Hi @v-jianboli-msft ,

 

Thanks for your answer.We are almost done

But my requirement here is I need to show the departments as filters to the report.(Need to show them in a slicer )

 

lbendlin
Super User
Super User

You would create groups in Power BI for this, no need for DAX

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.