[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-05。"],[],[],null,["# Maximizing code reusability with DRY LookML: Defining reusable lists of fields with the set parameter\n\n| **Note:** This page is part of the [Looker cookbook: Maximizing code reusability with DRY LookML](/looker/docs/best-practices/dry-lookml-cookbook).\n\nOne way to make your LookML projects more efficient and easier to maintain is with the LookML `set` parameter. The `set` parameter lets you group fields that may often be repeated throughout your project within the `fields` parameter or within drill fields. If you use a set to group repeated fields, you create a single place within the model where that group of fields can be maintained.\n\nThis page includes the following examples of using LookML sets to make your LookML projects more efficient and maintainable:\n\n- [Adding the same drill fields to multiple measures](#example_adding_the_same_drill_fields_to_multiple_measures): Define drill fields for details that your users commonly want to see when they drill into aggregations.\n- [Including or omitting a set of fields from an Explore](#example_including_or_omitting_a_set_of_fields_from_an_explore): Customize the Explore experience for users and simplify the list of fields that users can choose from in the field picker.\n\n| **Important:** If you use the `set` parameter in one view to reference a field that is from a second view, make sure that the second view is joined to the [Explore](/looker/docs/reference/param-explore-explore) where `set` is being used. Use the syntax `view_name.field_name` to reference fields from a joined view within a set.\n\nIngredients\n-----------\n\n- The LookML [`set` parameter](/looker/docs/reference/param-view-set)\n- The LookML [`fields` parameter (for Explores)](/looker/docs/reference/param-explore-fields)\n- The LookML [`drill_fields` parameter (for fields)](/looker/docs/reference/param-field-drill-fields)\n- The LookML [`drill_fields` parameter (for views)](/looker/docs/reference/param-view-drill-fields)\n\nPrerequisites\n-------------\n\n- [A configured LookML model](/looker/docs/generating-a-model#when_you_need_to_configure_models)\n- [Permissions to develop LookML](/looker/docs/admin-panel-users-roles#permission_sets)\n\nExample: Adding the same drill fields to multiple measures\n----------------------------------------------------------\n\nSuppose you want your users to be able to drill down to see more granular user details wherever they see sales metrics in Explores, Looks, or dashboards, so that selecting a value for the **Count** measure in the Explore UI opens a query on the fields **ID** , **City** , **State** , and **Country**:\n\nYou can create a set called `user_details` that includes the fields `id`, `city`, `state`, and `country` and then reference them in multiple measures for your users to drill into: \n\n\n set: user_details {\n fields: [id, city, state, country]\n }\n\nThe `user_details` set can be used to define a [drill field](/looker/docs/reference/param-field-drill-fields) for the `count` measure: \n\n\n measure: count {\n type: count\n drill_fields: [user_details*]\n }\n\nIn this example, the syntax `[set_name*]` is used to specify that the fields within the `user_details` will appear in the query results when you drill into the **Count** measure.\n\nYou can then reuse this set to create additional drill fields. For example, you can add the LookML code `drill_fields: [user_details*]` to the `order_count`, `total_sale_price`, and `average_sale_price` measures: \n\n\n measure: order_count {\n view_label: \"Orders\"\n type: count_distinct\n description: \"Number of orders\"\n sql: ${order_id} ;;\n drill_fields: [user_details*]\n\n }\n\n measure: total_sale_price {\n type: sum\n value_format_name: usd\n sql: ${sale_price} ;;\n drill_fields: [user_details*]\n }\n\n measure: average_sale_price {\n type: average\n value_format_name: usd\n sql: ${sale_price} ;;\n drill_fields: [user_details*]\n }\n\nAs with the **Count** measure, when a user selects a value for **Order Count** , **Total Sale Price** , or **Average Sale Price** in the Explore UI, Looker opens a window containing a query on the fields **ID** , **City** , **State** , and **Country**.\n\nIf you want to change anything about the drill fields, such as adding or removing a field, you would only have to update the `user_details` set.\n\nYou can also reference a set within the [`drill_fields` parameter of a view](/looker/docs/reference/param-view-drill-fields) to define drill fields for all measures within that view that do not already have drill fields specified at the field level.\n\nExample: Including or omitting a set of fields from an Explore\n--------------------------------------------------------------\n\nSuppose you want to simplify the Explore field picker for users by excluding fields that are not crucial for those users.\n\nFor example, suppose you have a `users` view that contains information about your customers, including fields for **ID** , **First Name** , **Last Name** , **Email** , and **Age** , as well as location fields like **City** , **State** , **Country** , and **Zip** . The `users` view is joined to the `orders` Explore:\n\nWhat if you want to exclude the **First Name** , **Last Name** , **Email** , **Age** , and **Gender** fields from the Explore for your users? You can create a set called `user_info` that lists the fields you want to exclude from the **Orders** Explore:\n\nThe LookML for the `user_info` set would look like this: \n\n\n set: user_info {\n fields: [first_name, last_name, email, age, gender]\n }\n\nTo define an **Orders** Explore with the label **Orders Without User Data** , join the `users` view to the `orders` Explore. Add the LookML code `fields: [ALL_FIELDS*, -users.user_info*]` to the `orders` Explore to include all fields except for the fields in the `user_info` set from the `users` view: \n\n\n explore: orders {\n fields: [ALL_FIELDS*, -users.user_info*]\n label: \"Orders Without User Data\"\n join: users {\n type: left_outer\n sql_on: ${orders.user_id} = ${users.id} ;;\n relationship: many_to_one\n }\n }\n\nBecause the `user_details` set is excluded from the Explore with the syntax `-users.user_details*` in the `fields` parameter of the `orders` Explore, the **Orders** view within the **Orders Without User Data** Explore omits the fields listed in the `users_user.info` set from the Explore field picker.\n\nYou can reuse the `user_info` set to omit these fields from the Explore UI for any other Explores to which the `users` view is joined. If you want to change anything about the `user_info` set, such as adding or removing a field, you would only have to update the `user_info` set."]]