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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Radz2707
Regular Visitor

Hey team ! Need help creating a filter based on columns .

I have survey data , having customer info, it has 50 flag columns having yes/ no values . I have to create a slicer having all these flag column names , such that if I click on a flag letters say HasPro , it should filter all visuals by HasPro=yes. 
P.S. I can't really unpivot the data as there are 15columns . 
a sample could be 

cust no . | survey wave| response date| iscitiezen | has policy | has pro | has premium | has PPU . 
All the columns after response date are having yes/ no values.Please note : these columns are not mutually exclusive so I can't create a single calculated column , that can be further used in a slicer.

9 REPLIES 9
Radz2707
Regular Visitor

Thanks , for the help team , however , my use case is a bit different and I had confiedential data in my data set do I was unable to Provide the sample . I tried all the above solutions , all did part ofthe job , but my requirement is a bit diffferent .

 

Hi @Radz2707 ,

As you mentioned that, you data is confidential. you can't able to share sample data. Based on your inputs , i have created sample data.

 

Please follow below steps.

 

1. Created sample data based on your column headers. please refer snap.

vdineshya_0-1750075657782.png

 

2.  Created disconnected table, to reprsent the flag names in slicer based on below DAX code.

FlagSelector = DATATABLE(
    "FlagName", STRING,
    {
        {"IsCitizen"},
        {"HasPolicy"},
        {"HasPro"},
        {"HasPremium"},
        {"HasPPU"}
    }
)
 
3.  Created measure with below DAX code.
 
FlagFilterMeasure =
VAR SelectedFlag = SELECTEDVALUE(FlagSelector[FlagName])
RETURN
    SWITCH(
        TRUE(),
        SelectedFlag = "IsCitizen", IF(MAX(SurveyData[IsCitizen]) = "Yes", 1, 0),
        SelectedFlag = "HasPolicy", IF(MAX(SurveyData[HasPolicy]) = "Yes", 1, 0),
        SelectedFlag = "HasPro", IF(MAX(SurveyData[HasPro]) = "Yes", 1, 0),
        SelectedFlag = "HasPremium", IF(MAX(SurveyData[HasPremium]) = "Yes", 1, 0),
        SelectedFlag = "HasPPU", IF(MAX(SurveyData[HasPPU]) = "Yes", 1, 0),
        1
    )
 
4. In  table visual, add Custono, SurveyWave columns. Add FlagSelector[FlagName] in slicer. and drag 'FlagFilterMeasure' measure in visual level filter and set the value ='1'.
 
5. Please refer the output snap and attched PBIX file.
vdineshya_1-1750076655979.png

 

If this information is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

v-dineshya
Community Support
Community Support

Hi @Radz2707 ,

Thank you for reaching out to the Microsoft Community Forum.

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

 

Thank you

Hi @Radz2707 ,

We haven’t heard from you on the last response and was just checking back to see , please provide sample data And, if you have any further query do let us know.

 

Thank you.

danextian
Super User
Super User

Hi @Radz2707 

What does this mean?

P.S. I can't really unpivot the data as there are 15columns . 

 

 It would be easier for anyone to provide a more feasible solution  had you provided a sample data which doesn't have to be confidential but actually represents the actual data, and your expected result from that. Ensure that we can easily copy-paste it.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
maruthisp
Solution Specialist
Solution Specialist

Hi Radz2707,

I tried to implement a solution based on your original post. Please check the below pbix file.
creating a filter based on columns.pbix

If this reply helped solve your problem, please consider clicking "Accept as Solution" so others can benefit too. And if you found it useful, a quick "Kudos" is always appreciated, thanks! 

 

Best Regards, 

Maruthi 

LinkedIn - http://www.linkedin.com/in/maruthi-siva-prasad/ 

X            -  Maruthi Siva Prasad - (@MaruthiSP) / X

ryan_mayu
Super User
Super User

could you pls provide some sample data (not only the headers) and the expected output?





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

Proud to be a Super User!




Ashish_Excel
Resolver V
Resolver V

Hi,

I do not understand what you mean by "I can't really unpivot the data as there are 15columns"?  Why can you not unpivot?

Shravan133
Super User
Super User

Generated by AI

 

🛠️ Solution Outline (Without Unpivoting)

  1. Create a Disconnected Table for Flags

Manually define a table listing all your flag column names.

Option 1: Use DAX to create it

FlagSelector =

DATATABLE(

    "FlagName", STRING,

    {

        {"IsCitizen"},

        {"HasPolicy"},

        {"HasPro"},

        {"HasPremium"},

        {"HasPPU"}

    }

)

Or create it in Power Query if you prefer.

  1. Create a Measure to Filter Based on Selected Flag

Here’s the trick: write a measure that checks the selected flag and filters rows accordingly.

SelectedFlagFilter =

VAR SelectedFlag = SELECTEDVALUE(FlagSelector[FlagName])

RETURN

    SWITCH(

        TRUE(),

        SelectedFlag = "IsCitizen", CALCULATE(COUNTROWS(SurveyData), SurveyData[IsCitizen] = "Yes"),

        SelectedFlag = "HasPolicy", CALCULATE(COUNTROWS(SurveyData), SurveyData[HasPolicy] = "Yes"),

        SelectedFlag = "HasPro", CALCULATE(COUNTROWS(SurveyData), SurveyData[HasPro] = "Yes"),

        SelectedFlag = "HasPremium", CALCULATE(COUNTROWS(SurveyData), SurveyData[HasPremium] = "Yes"),

        SelectedFlag = "HasPPU", CALCULATE(COUNTROWS(SurveyData), SurveyData[HasPPU] = "Yes"),

        BLANK()

    )

That measure gives you dynamic results — you can also use a version returning 1/0 (TRUE/FALSE) to use as a visual filter.

  1. Use it as a Visual-Level Filter

To filter visuals based on the selected flag:

  • Create a Boolean measure:

ShowRow =

VAR SelectedFlag = SELECTEDVALUE(FlagSelector[FlagName])

RETURN

    SWITCH(

        TRUE(),

        SelectedFlag = "IsCitizen", SurveyData[IsCitizen] = "Yes",

        SelectedFlag = "HasPolicy", SurveyData[HasPolicy] = "Yes",

        SelectedFlag = "HasPro", SurveyData[HasPro] = "Yes",

        SelectedFlag = "HasPremium", SurveyData[HasPremium] = "Yes",

        SelectedFlag = "HasPPU", SurveyData[HasPPU] = "Yes",

        TRUE()

    )

Then, drag this measure to the filter pane of your visuals, and set it to TRUE.

🔄 Result

Now, your slicer shows:

IsCitizen | HasPolicy | HasPro | HasPremium | HasPPU

And selecting, say, HasPro dynamically filters your visuals to only show customers where HasPro = "Yes" — without unpivoting or restructuring your data model.

⚠️ Notes

  • This method supports only 1 selection at a time. For multi-select, more complex logic (e.g. using IN) is needed.
  • The more flags you have, the longer the SWITCH gets — you might consider managing it via a helper table and relationship in more advanced models.

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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