Forum Discussion

RichardLinderma's avatar
1 year ago
Solved

Disabling buttons for conditions.

I have a parameter measure in Power BI that has a DAX formula of the following:

 

Parameter = {
("Products sold", NAMEOF(Invoice['ProductsSold']), 0),
("Profit", NAMEOF(Invoice[ProfitMade]), 1),
("Losses", NAMEOF(Invoice[LossesLost]), 2)
}

 

I also have the following, being used in a button slicer:

 

Parmeter_Title =
SWITCH(
TRUE(),
Parameter[Parameter]="Products sold","PRODUCTS SOLD",
Parameter[Parameter]="Profit","PROFIT MADE",
Parameter[Parameter]="Losses","MONEY LOST"
)

 

I want to edit the functions so that Profit and Losses are only accessible when the column hierarchy[data_source] equals either "company1", "company2" or "company3", and that otherwise the buttons are disabled and only Products Sold is viewable.

One thing to mention is that I want to try this on multiple datasets for companies. However, only the datasets for companies 1, 2 and 3 should have the buttons accessible (the column hierarchy[data_source] consists of only "company[a]" and "demo).

7 Replies

  • v-sshirivolu's avatar
    v-sshirivolu
    Community Support

    Hi RichardLinderma ,
    Thank you for reaching out to Microsoft fabric community.

    Try these steps - 

    Create a Disconnected Parameter Table

    Parameter = DATATABLE(
    "Label", STRING,
    {
    {"Products sold"},
    {"Profit"},
    {"Losses"}
    }
    )

    Create a Data Source Allowed Logic Measure
    IsCompanyAllowed =
    IF (
    SELECTEDVALUE('hierarchy'[data_source]) IN {"company1", "company2", "company3"},
    1,
    0
    )

    Create a Dynamic Title Measure
    Parameter_Title =
    VAR SelectedParam = SELECTEDVALUE('Parameter'[Label])
    VAR IsAllowed = SELECTEDVALUE('hierarchy'[data_source]) IN {"company1", "company2", "company3"}
    RETURN
    SWITCH(
        TRUE(),
        SelectedParam = "Products sold", "PRODUCTS SOLD",
        SelectedParam = "Profit" && IsAllowed, "PROFIT MADE",
        SelectedParam = "Losses" && IsAllowed, "MONEY LOST",
        BLANK()
    )

    Create a Button Visibility Measure
    IsButtonVisible =
    VAR SelectedParam = SELECTEDVALUE('Parameter'[Label])
    VAR IsAllowed = SELECTEDVALUE('Invoice'[data_source]) IN {"company1", "company2", "company3"}
    RETURN
    SWITCH(
        TRUE(),
        SelectedParam = "Products sold", 1,
        SelectedParam IN {"Profit", "Losses"} && IsAllowed, 1,
        0
    )

    Create Two Versions of Each Button
    For each metric, set up:

    • ON Button (visible for allowed companies)
    • OFF Button (grayed out or with a "Not available" tooltip)

    Name these in the selection pane as:

    • Profit Button ON / OFF
    • Losses Button ON / OFF
    • Products Sold Button ON / OFF (optional)


    Stack Buttons Over Each Other

    • Place ON and OFF versions in the same position
    • Use the Selection Pane to manage and name them
    • Control visibility with conditions

    Create Bookmarks to Show/Hide the Correct Buttons
    Bookmark 1 – Allowed Companies
    Show ON buttons for Profit and Losses, hide OFF buttons. Save as: Allowed Companies
    Bookmark 2 – Other Companies
    Show OFF buttons, hide ON versions. Save as: Other Companies
    Be sure to turn off the "Data" option in bookmark settings.

    Assign Buttons to Toggle Bookmarks
    Add shapes or slicer buttons for Allowed Companies and Other Companies. These will control which button set is visible.
    Test the Setup
    Select a company using the slicer and verify that the correct buttons appear accordingly.


    Find the attached .pbix file for your reference

    • v-sshirivolu's avatar
      v-sshirivolu
      Community Support

      Hi RichardLinderma,

       

      Apologies for the delayed response.

      I am currently looking into your issue as a priority and will update you as soon as possible.

      Thank you for your Patience.

      • RichardLinderma's avatar
        RichardLinderma
        Helper I

        Don't worry about it. I already fixed it myself.

         

        However, I do have another issue that I shall post to the forums.