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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mpeters1988
Frequent Visitor

Calculated Field for Slicer

Hi everybody,

 

I'm trying to find out whether or not Power BI allows you to create a column name and use that as the actual Field in a Slicer. As a test I created the following tables/datamodel:

 

DataFields tableDataFields tableDatamodelDatamodel

 

Now I've tried to create a calculated column/measure, based on a SWITCH statement (see example) that contains all names from the  'Fields' table and all column from the 'Calendar' table, but I'm running into multiple errors, even though it looks like everything should be valid.

 

example:

DynamicColumn = SWITCH(
DataFields[FieldNames];
"ISO_WEEK_NUMBER"; WeekCalendar[ISO_WEEK_NUMBER];

"MONTH_VALUE"; WeekCalendar[MONTH_VALUE];

"None"

)

 

Has anyone tried this before? I couldn't find any related posts, mainly because it's quite hard to define in a search argument.

 

EDIT: The reason I'm trying to do this is to dynamically fill a single slicer so a user doesn't need dozens of slicers on one page, but only two: one to select the field to filter, one to do the actual filtering/slicing.

 

I'm not aware of any reason why this shouldn't be possible in Power BI, but I might be wrong. As far as I know this is a possibility in QlikView and it's a great way to save screen space. I'm open to any other tips/suggestions on how to do these kind of things in Power BI.

 

Thanks in advance!

 

Maarten

1 ACCEPTED SOLUTION

Hi @mpeters1988,

The reason I'm trying to do this is to dynamically fill a single slicer so a user doesn't need dozens of slicers on one page, but only two: one to select the field to filter, one to do the actual filtering/slicing.

In your scenario, you should be able to use the Unpivot option in Query Editor to unpivot those columns(the value type has tp be the same) that you want to use as Slicers.

 

After unpivoting, you'll get a Attribute column(Field names), Value column(Values). Then you can use only these two columns as Slicers on the report. For more details about how to use the Unpivot option in Power BI, you can refer to this article. Smiley Happy

 

unpivot.PNGr2.PNG

 

Regards

View solution in original post

4 REPLIES 4
v-ljerr-msft
Employee
Employee

Hi @mpeters1988,

 

What's this calculate field used for? Could you be more precisely with your expected result? Smiley Happy

 

In addition, not like measures, calculate columns/tables are computed during database processing(e.g. data refresh) and then stored in the model, they do not response to user selections on the report.

 

So it is not possible to create a calculate column/table can change dynamically with user selections on the report.

 

Regards

It is not clear from your post how your tables are structured. E.g. Your calendar table description makes sense but then the fields table description seems to use some different design, and it is not clear what columns it has. You haven't provided I formation about how your tables are joined, if at all. Without this information it is impossible to give a formula that will work. 

 

It is not clear if you actually need this column - power bi is designed to allow table to work together without the need to consolidate columns. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

@MattAllington: I've edited my post with an example report I made in Power BI, so I hope that sheds some light on what I'm trying to do!

 

All I'm trying to do is to fill a slicer dynamically based on user selections.

 

@v-ljerr-msft: So if I understand correctly the only way to do this would be a measure and from what I understand, a measure can only return a single value and there's no way a measure or a calculated column can be evaluated so it can dynamically show a different field in the slicer, even though it is possible to construct the name of that field?

Hi @mpeters1988,

The reason I'm trying to do this is to dynamically fill a single slicer so a user doesn't need dozens of slicers on one page, but only two: one to select the field to filter, one to do the actual filtering/slicing.

In your scenario, you should be able to use the Unpivot option in Query Editor to unpivot those columns(the value type has tp be the same) that you want to use as Slicers.

 

After unpivoting, you'll get a Attribute column(Field names), Value column(Values). Then you can use only these two columns as Slicers on the report. For more details about how to use the Unpivot option in Power BI, you can refer to this article. Smiley Happy

 

unpivot.PNGr2.PNG

 

Regards

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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