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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Vil
Frequent Visitor

Custom visuals ItemFlagsSelection formatting settings

I'm trying to use flags selection in my Power BI Custom Visual. In settings.ts I have defined the formatting setting like this:

 

Vil_1-1717230625042.png

 

An it matches this one in cababilities.json
Vil_2-1717230651305.png

 

It appears in formatting pane like this (as it should):

Vil_3-1717230689970.png

 

Issue is that when I select let's say "Left" and "Right" the later one is only saved to options.dataViews[0].metadata.objects. Any help how to work with flag selections? How can I get each selected value?

 
Vil_0-1717230515714.png

 

1 ACCEPTED SOLUTION
v-asoronov
Microsoft Employee
Microsoft Employee

Hello @Vil , @v-shex-msft , @EscritórioDados , @dm-p , PowerBI custom visuals developer is here.

This reply is edited.

 

There are 2 components to work with flags - ItemFlagsSelection and AutoFlagsSelection. AutoFlagsSelection needs you only to specify default value and enumeration values in capabilities.json. ItemFlagsSelection needs you to specify enumeration values in formatting settings card, but in capabilities.json you may just leave empty array.

 

But it seems that there's a bug with ItemFlagsSelection. It gives correct value in dataView, but does not display which flags are enabled, instead it resets all of them as if nothing is checked. On contrary AutoFlagsSelection works as expected, so I suggest you to use it. Here's public repo with simple example how to use AutoFlagsSelection.

 

Also, I'll provide necessary steps below.

1. Specify enumeration values in capabilities.json

vasoronov_0-1722607601148.png

 

2. Create AutoFlagsSelection slice with default value. I'm using defaut value as empty string so no flags are checked.

vasoronov_1-1722607683446.png

 

3. Get the value from formattingSettings. It's represented as Number and each bit corresponds to the single flag. If the number is equal to zero, then no flags are enabled. It's a good practice to use TypeScript enums and check values that are comming from PowerBI.

vasoronov_3-1722608144827.png

 

vasoronov_4-1722608187847.png

 

 

View solution in original post

18 REPLIES 18
EscritórioDados
Frequent Visitor

I has use the steps that @v-asoronov post, didn't work correctly.
The checkbox was unchecked automatically after I have click in it.

I try a lot of thechnics to maintain the item state, using update method. Nothing works.

I would like to see one full example with only the ItemFlagsSelection in a card on formatting pane. Parts of codes doesn't resolve the trouble, because never works when I put into files of project on VSCode and test in app.powebi.com.

Is difficul to do this?

Hello @EscritórioDados @Vil , here’s public repo where you can see how to work with AutoFlagsSelection.

After tinkering with ItemFlagsSelection I think that there’s a bug with TypeScript definition of ItemFlagsSelection and another bug how it’s displayed in formatting pane.
What I mean is that the value is passed into dataView successfully, but it’s not displayed in formatting pane. Instead all flags/checkbox items in formatting pane are reset.
 
This does not happen with AutoFlagsSelection. Please try the example and provide a feedback.
v-asoronov
Microsoft Employee
Microsoft Employee

Hello @Vil , @v-shex-msft , @EscritórioDados , @dm-p , PowerBI custom visuals developer is here.

This reply is edited.

 

There are 2 components to work with flags - ItemFlagsSelection and AutoFlagsSelection. AutoFlagsSelection needs you only to specify default value and enumeration values in capabilities.json. ItemFlagsSelection needs you to specify enumeration values in formatting settings card, but in capabilities.json you may just leave empty array.

 

But it seems that there's a bug with ItemFlagsSelection. It gives correct value in dataView, but does not display which flags are enabled, instead it resets all of them as if nothing is checked. On contrary AutoFlagsSelection works as expected, so I suggest you to use it. Here's public repo with simple example how to use AutoFlagsSelection.

 

Also, I'll provide necessary steps below.

1. Specify enumeration values in capabilities.json

vasoronov_0-1722607601148.png

 

2. Create AutoFlagsSelection slice with default value. I'm using defaut value as empty string so no flags are checked.

vasoronov_1-1722607683446.png

 

3. Get the value from formattingSettings. It's represented as Number and each bit corresponds to the single flag. If the number is equal to zero, then no flags are enabled. It's a good practice to use TypeScript enums and check values that are comming from PowerBI.

vasoronov_3-1722608144827.png

 

vasoronov_4-1722608187847.png

 

 

@Vil @EscritórioDados @v-shex-msft @dm-p , hello again! The issue is fixed and published in powerbi-visuals-utils-formattingmodel@6.0.3. Please, update the package and try it out!

 

Here's the bug explained, if you want to learn.

v-asoronov
Microsoft Employee

I tried and the same thing happens. It only keeps the items marked until you change the formatting or visual panel, cleaning everything afterwards.
I put code in the visual update to try to mark it, but the previous box returns to the original value on its own, marking only one. I can only keep one.

I sent the email because of this. Would it be possible to put a simple example on github?

Alexandre

Thanks @v-asoronov for the insights!

 

However, I did not succeed in my testing either. I was planning to do more thorough testing at a later time. In the meantime, GitHub example that @EscritórioDados mentioned would be appreciated!

 

Thanks! 

v-asoronov
Microsoft Employee
Microsoft Employee

Hello @Vil , I created the GitHub example as you suggested and also modified my example. Please, read above.

Hello @v-asoronov

 

Thank you! Example was a big help and I finally got it to working. I'll mark this as accepted solution. 

 

Once again thanks!

Vil
Frequent Visitor

Hello @v-shex-msft,

 

Thanks for the reply. I created a simple project for this here. In settings.ts I have defined ItemFlagsSelection like this:

 

class DataPointCardSettings extends FormattingSettingsCard {
    borderOptions: powerbi.IEnumMember[] = [
        { value: 0, displayName: "Top" },
        { value: 1, displayName: "Bottom" },
        { value: 2, displayName: "Left" },
        { value: 3, displayName: "Right" },
    ];
    border = new formattingSettings.ItemFlagsSelection({
        name: "border",
        displayName: "Border",
        value: null,
        items: this.borderOptions,
    });

    name: string = "dataPoint";
    displayName: string = "Border";
    slices: Array<FormattingSettingsSlice> = [this.border];
}

 

and it match this capabilities.json

 

    "objects": {
        "dataPoint": {
            "properties": {
                "border": {
                    "type": { 
                        "enumeration": []
                    }
                }
            }
        }
    },

 

 

In visual.ts there is just log and show the selected formatting settings value. It is not working as it should? It's showing only last value that I select and not all selected, if there are many. So any help how should I use ItemFlagsSelection?

HI @Vil,

Perhaps you can refer to the official document 'Adding custom formatting options' part if help for your scenario:

Add formatting options to a Power BI custom visual - Power BI | Microsoft Learn

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hello @v-shex-msft ,

Thanks for keeping this discussion active. I have readed documentation many times but there is no example of the flagsSector. I have many other kind of formattings settings in my visual and they are working fine. This flagSelector is just something I cannot get to work. 

I found a workaround but I'm not happy with it. But let's see, I'll hope someone finds the answer!

I tried many configurations, but none of them worked. The problem for me is that I don't know how to show the checkbox as checked when it appears for the first time. If I can solve this, using the update function will be easy. I have spent many hours on this, but it never works.

Thanks @EscritórioDados for the try. I spent also countless hours trying to solve it, but in the end, I had to proceed with a workaround. It's a shame these are so poorly documented. Another formatting setting type, "FieldPicker," is also similar that I just cannot get to work.

Hi @Vil,

 

I had similar challenges with the FieldPicker type, so I contacted MS for support (as they don't monitor these forums). They confirmed that it is unsupported, is included in the typings due to an oversight, and would be removed from the API in a subsequent version. While this is annoying, I got some closure on what I was trying to do (although I don't have any other workaround for what I want).

 

Due to your thread, I reviewed the ItemFlagsSelection implementation. I couldn't get it to work as expected, and I'd suggest you do the same as me - contact MS at pbicvsupport@microsoft.com for confirmation on how it should work with a suitable example, as the documentation is unclear. They may also confirm the above, which will again be annoying, but you will know that your workaround may be how you have to do it.

 

From my own perspective, I think for this to work how we would want, this needs a CompositeSlice (like FontControl or MarginPadding) where the individual properties (left, right, top, bottom) can be accessed and assigned.

 

Good luck,

 

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Vil
Frequent Visitor

Hi @dm-p,

 

Thanks for the hint. I'll do that. 

 

Have a good one!

v-asoronov
Microsoft Employee
Microsoft Employee

Please, look at my reply. There's an explanation how to make it work.

I tried with another fields to store de values. But the checkbox needs value equals to zero to be checked and it's impossible to know wich item is clicked.
The itemFlagsSelection returns zero if the item is checked. The value of the group return the first item. It's impossible to know where the user have clicked.

 

v-shex-msft
Community Support
Community Support

Hi @Vil ,

Can you please share some more detail information about this issue? They should help us clarify your scenario and test to troubleshoot.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors