知識庫

How to Sort Data in the Order of Parameter Values Specified


發佈時間 : 14 Mar 2024
上次修改日期 : 15 Mar 2024

問題

Assume that you have the following view. In this example, only data for the year specified by the parameters is displayed to compare sales for each year. 

User-added image

In this case, even if the Year 1 parameter is specified to be greater than the Year 2 parameter as follows, the data will be displayed in ascending order by year. How can we sort the data in the order specified by the first and second parameters?

User-added image

環境

  • Tableau Desktop

答案

Follow along in the sample packaged workbook found in the Attachments section to review the steps below.

User-added image

1. Add YEAR(Order Date) to Rows.
2. Add SUM(Sales) to Text.
3. Create parameters and configure them as follows:
 User-added image User-added image
4. Create a calculated field and name it Filter with the following formula:
YEAR([Order Date]) = [Year 1]
OR
YEAR([Order Date]) = [Year 2]
5. Add Filter to Filters shelf and select TRUE.
6. Create a calculated field and name it Sort with the following formula:
IF YEAR([Order Date]) = [Year 1] THEN 1 ELSE 2 END
7. Right-click YEAR(Order Date) in Rows and select Sort. Configure it as follows:
 User-added image
這篇文章是否解決了問題?