You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅用SAMEPERIODLASTYEAR函数精准计算去年同期单日销售额?

How to Get Precise Date-Matched Sales with SAMEPERIODLASTYEAR

Absolutely! You don’t need to resort to manual daily calculations—your existing formula is actually already set up to do precise date matching, and the SAMEPERIODLASTYEAR function is fully capable of this. Let me clarify why you’re seeing full-month results right now, and how to get the day-level precision you want.

The Core Issue: Context Matters

The reason your current formula returns the full month of last year is because your filter context is set to an entire month (e.g., you’re viewing data for January 2024, so SAMEPERIODLASTYEAR returns all dates in January 2023). But the function itself is designed to map dates one-to-one:

  • For a single date like 2024-01-05, it returns exactly 2023-01-05
  • For a range of dates (like a full month), it returns the corresponding range from last year

How to Get Precise Date Matches

You don’t need to change your formula at all—just adjust how you’re viewing or filtering the data:

  • View at the day level: Add Dates[Date] to your table/visualization (instead of just month/year). Your Sales Last Year measure will automatically show the sales for the exact same day last year for each row.
  • Filter to individual dates: If you’re testing with a single date filter (e.g., 2024-01-10), the measure will only calculate sales for 2023-01-10.

Example of How It Works

Let’s say your [Sum of Sales] measure calculates daily sales. When you use:

Sales Last Year := CALCULATE([Sum of Sales], SAMEPERIODLASTYEAR(Dates[Date]))
  • If your visual shows rows for 2024-01-01, 2024-01-02, etc., Sales Last Year will show the sales from 2023-01-01, 2023-01-02, etc., respectively.
  • If you filter to the entire month of January 2024, the measure will sum all sales from January 2023—but that’s because the context is the full month, not a flaw in the function.

Edge Case: Leap Years

One thing to note: For February 29 in a leap year, SAMEPERIODLASTYEAR won’t return any date (since non-leap years don’t have that day), so the measure will return blank for that date—this is correct behavior for precise date matching.

So to recap: Your existing formula is perfect for precise date matching. The "full month" result you’re seeing is just a side effect of your current context, not a limitation of the function.

内容的提问来源于stack exchange,提问作者MBrann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:14:24