简体   繁体   中英

Calculating YTD MTD in Tableau with fixed LOD (level of detail)

Trying to make a report in Tableau that would show the following sales stats:

  • sales yesterday
  • sales week-to-date
  • sales month-to-date
  • sales run-rate (30 days) - based on month-to-date calculation

The problem is that the data source is Shopware DB and it stores all historical states of an order: when it was created, when it was paid but not shipped, when it was shipped, when it was closed. Ie duplicate orders.

The report is connected directly to Shopware DB without data prep. Thus, to remove the duplicate entries for each order state I am using a FIXED level of detail calculation to calclate the correct SUM:

{Fixed [Order Number],[identifier]:MIN([total_price])}

However, when I am trying to use either of solutions for MTD, YTD calculations that I found online based on this fixed calculated field "Correct SUM", I am getting totally strange numbers, which i am not even able to understand (they are much more then what I have, for example, in Power BI for the same data source; 17k USD instead of 238 USD, 65k USD instead of 55k USD, etc.).

I tried using the following calculated fields:

  1. SUM IF: SUM( IF MONTH([Order Date])=MONTH(TODAY()) THEN [Correct SUM] END

  2. True/False calculated field used as a filter (as described here ): [Order Date] <= TODAY() AND DATETRUNC( "month", [Order Date]) = DATETRUNC("month", TODAY())

Can anyone advise what to do next?

您应该创建字段 MTD_ Sales: IIF (year ([order date] = year (today()) and month ([order date] = year (today()) and [order date] < = today(), 1, 0); 首先将字段MTD_sales设置为维度,然后将该字段放入tableau的过滤器中,选择“1”,然后就可以选择你想要的维度和值了,MTD_Sales指的是MTD所在的日期遇到了。类似地,YTD 也是如此

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM