PowerBi - 如何在矩阵中显示多个总列?

发布于 2025-01-18 07:38:55 字数 276 浏览 0 评论 0原文

我有一个切片机,可以从中选择要在矩阵上显示的几周。当前,矩阵仅在所有列的末尾显示总列,这基本上总结了所有值。

但是我想显示多个总列(每个月一个又一个)。就像一个月结束后,总的专栏等。

I have a slicer from which I can select weeks that I want to show on a matrix. Currently, the matrix only shows the total column at the end of all columns basically summing up all the values.

But I want to show multiple total column (One after each month). Like after the End Of Weeks of one month a total column and so on.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

度的依靠╰つ 2025-01-25 07:38:55

您不能简单地创建计算的列MEATUR来解决此问题。实际上,您可以使用计算的列使用一些逻辑,但是有一种更有效的方法。为了实现目标,您必须根据日期列创建计算的表。您可以使用该逻辑为视觉效果创建任何自定义标签。

在我们开始在这里深入DAX之前,让我们创建一个日历表。

Calendar = 
VAR _minSalesDate = CALCULATE( MIN( Sales[Date] ), ALL( Sales ) )
VAR _maxSalesDate = CALCULATE( MAX( Sales[Date] ), ALL( Sales ) )
RETURN
ADDCOLUMNS(
    CALENDAR( _minSalesDate, _maxSalesDate ),
    "Month", MONTH( [Date] ),
    "MonthYear", MONTH( [Date] ) & "-" & YEAR( [Date] )
)

现在,当我们拥有带有日期和其他字段的表格时,我们可以开始为此特定情况创建解决方案。

创建一个新的计算表如下:

CustomCategories = 
UNION(
    SELECTCOLUMNS(
        SUMMARIZE(
            'Calendar', 
            'Calendar'[Date], 
            'Calendar'[Sorter]
        ),
    "Key", 'Calendar'[Date],
    "Label", 'Calendar'[Date], 
    "LabelSorter", 'Calendar'[Sorter]
    ),
    ADDCOLUMNS(
        SELECTCOLUMNS(
            SUMMARIZE(
                'Calendar', 
                'Calendar'[Date], 
                'Calendar'[MonthYear],
                'Calendar'[Sorter]
            ),
            "Key", 'Calendar'[Date],
            "Label", 'Calendar'[MonthYear]
        ),
        "LabelSorter", CALCULATE( MAX( 'Calendar'[Sorter] ), ALLEXCEPT( 'Calendar', 'Calendar'[MonthYear] ) ) + 0.5
    ),
    SELECTCOLUMNS(
        ADDCOLUMNS(
            SUMMARIZE(
                'Calendar',
                'Calendar'[Date],
                'Calendar'[Sorter]
            ),
            "LabelSorter", CALCULATE( MAX( 'Calendar'[Sorter] ), ALL( 'Calendar' ) ) + 1
        ),
        "Key", 'Calendar'[Date],
        "Label", "Total",
        "LabelSorter", [LabelSorter]
    )
)

请注意,DAX上面的最后一部分添加total是可选的。

创建表后,转到数据视图,选择customCategories表,选择标签列,然后按labelsorter对列进行排序(您将在功能区找到一个选项)。然后返回到您的模型视图,并在customCategoriesdate> date列之间设置一个关系。

完成上述所有内容后,请切换回报告视图。从表Visual中删除日期列,然后用新创建的LabelCustomCategories表替换它。

现在,您应该看到所需的结果。

希望有帮助!

问候,
arek

You cannot simply create a Calculated column or Measure to solve this problem. Actually, you can use some logic with Calculated column, but there is a more efficient way. To achieve the goal, you have to create Calculated table based on your date column. You can use that logic to create any custom label for your visuals.

Before we start diving into deep DAX here, let's create a calendar table.

Calendar = 
VAR _minSalesDate = CALCULATE( MIN( Sales[Date] ), ALL( Sales ) )
VAR _maxSalesDate = CALCULATE( MAX( Sales[Date] ), ALL( Sales ) )
RETURN
ADDCOLUMNS(
    CALENDAR( _minSalesDate, _maxSalesDate ),
    "Month", MONTH( [Date] ),
    "MonthYear", MONTH( [Date] ) & "-" & YEAR( [Date] )
)

Now, when we have the table with our dates and additional fields, we can start creating a solution for this particular case.

Create a new calculated table as follows:

CustomCategories = 
UNION(
    SELECTCOLUMNS(
        SUMMARIZE(
            'Calendar', 
            'Calendar'[Date], 
            'Calendar'[Sorter]
        ),
    "Key", 'Calendar'[Date],
    "Label", 'Calendar'[Date], 
    "LabelSorter", 'Calendar'[Sorter]
    ),
    ADDCOLUMNS(
        SELECTCOLUMNS(
            SUMMARIZE(
                'Calendar', 
                'Calendar'[Date], 
                'Calendar'[MonthYear],
                'Calendar'[Sorter]
            ),
            "Key", 'Calendar'[Date],
            "Label", 'Calendar'[MonthYear]
        ),
        "LabelSorter", CALCULATE( MAX( 'Calendar'[Sorter] ), ALLEXCEPT( 'Calendar', 'Calendar'[MonthYear] ) ) + 0.5
    ),
    SELECTCOLUMNS(
        ADDCOLUMNS(
            SUMMARIZE(
                'Calendar',
                'Calendar'[Date],
                'Calendar'[Sorter]
            ),
            "LabelSorter", CALCULATE( MAX( 'Calendar'[Sorter] ), ALL( 'Calendar' ) ) + 1
        ),
        "Key", 'Calendar'[Date],
        "Label", "Total",
        "LabelSorter", [LabelSorter]
    )
)

Note that the last part of above DAX adding Total is optional.

Once the table has been created, go to the Data view, select CustomCategories table, select Label column and sort the column by LabelSorter (you will find an option on the ribbon). Then go back to your Model view and set a relationship between CustomCategories and your Fact table on Date column.

When you have done with all stuff above, switch back to the Report view. Remove the date column from your table visual and replace it with the newly created Label from CustomCategories table.

Now you should see the desired results.

Hope that helps!

Regards,
Arek

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文