计算YTD,MTD,WTD,Power BI中的交易计数

发布于 2025-02-04 05:36:06 字数 675 浏览 4 评论 0原文

我有1行的1个桌子。看起来像这样:

------------------------------------------------
StoreId| PostingDate | SalesAmt
MAIN   | 2021-02-04  | 100
WEST   | 2021-08-11  | 15
WEST   | 2021-09-11  | 36
MAIN   | 2021-11-11  | 78
MAIN   | 2021-04-11  | 56
------------------------------------------------

不久之后...

现在,我想在Power BI中作为桌子产生以下内容:

--------------------------------------------
StoreId| YTD | MTD | WTD | TransactionCount |
WEST   |5,447| 800 | 74  |      1,475       |
MAIN   |4,500| 421 | 15  |      1,855       |
--------------------------------------------

我该如何实现?我对此非常陌生,所以我不知道该怎么做。 我一直在阅读DAX和Power查询,但也许DAX适合此?

I have 1 table with multiple rows. It looks something like this:

------------------------------------------------
StoreId| PostingDate | SalesAmt
MAIN   | 2021-02-04  | 100
WEST   | 2021-08-11  | 15
WEST   | 2021-09-11  | 36
MAIN   | 2021-11-11  | 78
MAIN   | 2021-04-11  | 56
------------------------------------------------

And soon and so forth...

Now I want to produce the following in the Power BI as Table:

--------------------------------------------
StoreId| YTD | MTD | WTD | TransactionCount |
WEST   |5,447| 800 | 74  |      1,475       |
MAIN   |4,500| 421 | 15  |      1,855       |
--------------------------------------------

How can I achieve that? I am very new to this so I don't know how to do it.
I have been reading DAX and Power Query but maybe DAX is suitable for this?

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

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

发布评论

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

评论(1

夏末 2025-02-11 05:36:07

我以为您的数据看起来像这样。我添加了2022年的数据。
另外,我假设没有未来的日期,观察结果是过去发生的交易。

Table

StoreIDPostingDateSalesamt
West16/01/2021141
Main24/01/2021221
West25/01/2021119
Main18/04/2021209
Main22/04/2021220
Main24/04/04/04/2021167 West 167 West 167
West16/11 /2021224
WEST03/02/2022155
MAIN07/02/2022236
WEST11/02/2022216
WEST23/03/2022135
MAIN28/05/2022153
WEST01/06/2022121

日历表

计算的 在下面工作,您需要创建一个日历表。
表的第一次日期到今天。
如果您的日历表不同,时间智能函数将无法工作。

Calendar = CALENDAR(MIN('Table'[PostingDate]),TODAY())

并将日历表标记为日期表。

销售金额

Sales Amount = sum('Table'[SalesAmt])

WTD

假设您的一周在星期一开始。

WTD = 
VAR WeekStart = TODAY() - WEEKDAY(today(),2)
RETURN
CALCULATE([Sales Amount],'Table'[PostingDate]>=WeekStart)

MTD:

MTD = 
TOTALMTD([Sales Amount],'Calendar'[Date])

YTD

YTD = 
TOTALYTD([Sales Amount],'Calendar'[Date])

I assumed your data looks like this. I've added data for the year 2022.
Also, I'm assuming there aren't future dates, the observations behave as transactions that happened in the past.

Table

StoreIDPostingDateSalesAmt
WEST16/01/2021141
MAIN24/01/2021221
WEST25/01/2021119
MAIN18/04/2021209
MAIN22/04/2021220
MAIN24/04/2021167
WEST16/11/2021224
WEST03/02/2022155
MAIN07/02/2022236
WEST11/02/2022216
WEST23/03/2022135
MAIN28/05/2022153
WEST01/06/2022121

Calendar Table

For the calculations below to work, you need to create a calendar table.
It goes from the first date of Table until today.
If your calendar table is different the time intelligence function will not work.

Calendar = CALENDAR(MIN('Table'[PostingDate]),TODAY())

And mark the Calendar table as a Date Table.

enter image description here

Sales Amount

Sales Amount = sum('Table'[SalesAmt])

WTD

Assumes your week starts on Monday.

WTD = 
VAR WeekStart = TODAY() - WEEKDAY(today(),2)
RETURN
CALCULATE([Sales Amount],'Table'[PostingDate]>=WeekStart)

MTD:

MTD = 
TOTALMTD([Sales Amount],'Calendar'[Date])

YTD

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