Skip to content

Commit

Permalink
Merge pull request dbt-labs#248 from fishtown-analytics/clrcrl/distin…
Browse files Browse the repository at this point in the history
…ct-pivot

Add distinct argument to pivot macro. fka dbt-labs#213
  • Loading branch information
Claire Carroll authored Jun 29, 2020
2 parents 00a589a + 67a0f72 commit bdc7c81
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion macros/sql/pivot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Arguments:
then_value: Value to use if comparison succeeds, default is 1
else_value: Value to use if comparison fails, default is 0
quote_identifiers: Whether to surround column aliases with double quotes, default is true
distinct: Whether to use distinct in the aggregation, default is False
#}

{% macro pivot(column,
Expand All @@ -48,9 +49,11 @@ Arguments:
suffix='',
then_value=1,
else_value=0,
quote_identifiers=True) %}
quote_identifiers=True,
distinct=False) %}
{% for v in values %}
{{ agg }}(
{% if distinct %} distinct {% endif %}
case
when {{ column }} {{ cmp }} '{{ v }}'
then {{ then_value }}
Expand Down

0 comments on commit bdc7c81

Please sign in to comment.