如何将2列值的计数显示为具有分组值作为行的枢轴表?

发布于 2025-02-02 06:59:03 字数 602 浏览 3 评论 0原文

我在Excel中有一个数据表,如下所示。

我正在尝试制作一个枢轴表,如下所示,预计每周的数据将增长。

当前的枢轴表使用数据模型,因此我相信我仅限于措施,而没有计算的字段(如果我错了,请正确)。

我尝试创建2个数据模型并基于周创建一个关系,但是由于值不是唯一的,因此不允许使用。获取售出的商品可能是我需要的缺少的作品。我认为应通过创建措施找到添加的项目和已销售项目之间的差异来解决库存列。

我一直在拔头发,试图解决这个问题。我觉得应该有可能,我只是错过了我面前的明显解决方案。

I have a data table in Excel simplified as below.

Raw Data

I am trying to make a Pivot Table as below, with Week Data expected to grow each week.

Pivot Data

Current Pivot Table uses Data Models, so I believe I am limited to Measures and no Calculated Fields (correct me if I am wrong).

I have tried creating 2 Data Models and create a relationship based on Week, but it is not allowed since the values are not unique. Getting the Items Sold count might be the missing piece I need. I think Inventory column should be solved by creating a measure to find the difference between Items Added and Items Sold.

I have been pulling my hair out trying to solve this. I feel it should be possible, and I am just missing the obvious solution in front of me.

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

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

发布评论

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

评论(1

疯了 2025-02-09 06:59:03

假设:

  1. 您的源表被称为 data
  2. 您有另一个名为 Weeks 的表,该表包含一个名为 Week 的单列,其中包含所有列的独特列表在 data 表中找到的几周,例如“ Week01”,“ Week02”,“ Week03”,“ Week04”,“ Week05”,

首先在 data之间建立两个关系 Weeks 表格,一张添加的周列(应为 Active ),而在上售出的一周列(应该是不活动)。

然后创建以下测量

Items Added:=COUNTROWS( Data )

Items Sold:=0
    + CALCULATE(
        COUNTROWS( Data ),
        USERELATIONSHIP ( Data[Sold Week], Weeks[Week] )
    )

Inventory:=VAR ThisWeek =
    MIN( Weeks[Week] )
VAR CumulativeAdded =
    CALCULATE( [Items Added], Weeks[Week] <= ThisWeek )
VAR CumulativeSold =
    CALCULATE(
        [Items Sold],
        FILTER(
            ALL( Weeks ),
            Weeks[Week] <= ThisWeek
                && NOT ( ISBLANK( Weeks[Week] ) )
        )
    )
RETURN
    CumulativeAdded - CumulativeSold

然后可以将其放在 Week Weeks Weeks 表的 Week 列旁边的枢轴表中。

该表中可能存在(空白)行,如果需要,您可以过滤掉。

Assuming:

  1. Your source table is named Data
  2. You have another table named Weeks which comprises a single column named Week and which contains a distinct list of all weeks to be found in the Data table, e.g. "WEEK01", "WEEK02", "WEEK03", "WEEK04", "WEEK05"

First create two relationships between the Data and Weeks tables, one to the Added Week column (which should be active), and one to the Sold Week column (which should be inactive).

Then create the following measures:

Items Added:=COUNTROWS( Data )

Items Sold:=0
    + CALCULATE(
        COUNTROWS( Data ),
        USERELATIONSHIP ( Data[Sold Week], Weeks[Week] )
    )

Inventory:=VAR ThisWeek =
    MIN( Weeks[Week] )
VAR CumulativeAdded =
    CALCULATE( [Items Added], Weeks[Week] <= ThisWeek )
VAR CumulativeSold =
    CALCULATE(
        [Items Sold],
        FILTER(
            ALL( Weeks ),
            Weeks[Week] <= ThisWeek
                && NOT ( ISBLANK( Weeks[Week] ) )
        )
    )
RETURN
    CumulativeAdded - CumulativeSold

which can then be placed in a Pivot Table alongside the Week column from the Weeks table.

A (blank) row may be present in this table, which you can filter out if you wish.

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