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

DAX技术咨询:统计general_report表上月创建记录数的实现问题

Fixing Custom Column for Counting Last Month's Entries in Power BI

Hey there! Let's break down why your custom column attempt didn't work and get you a working solution, plus fix up that existing measure while we're at it.

First: Spot the Issue in Your Original Measure

Your current measure uses TODAY() - MONTH(TODAY()) to calculate "one month ago"—but this is a mistake! MONTH(TODAY()) returns a number between 1-12 (like 10 for October), so you're subtracting N days instead of rolling back a full calendar month. For example, if today is October 15, you'd be subtracting 10 days to get October 5, not September 15.

The correct way to get the date exactly one month prior is using the EDATE function:

_created_last_month = 
COUNTROWS(
    FILTER(
        general_report,
        [Created] >= EDATE(TODAY(), -1)
    )
)

Why Your Custom Column Failed

Custom columns calculate a value for every row in your table, whereas measures calculate values dynamically based on filters. If you tried to put COUNTROWS directly in a custom column, it would return the total number of rows in the filtered table for every single row—not a row-specific flag to count later.

Step-by-Step Custom Column Solution

Here's how to create a working custom column setup to count last month's entries:

  1. Validate Your [Created] Column Type
    First, make sure your [Created] column is set to a Date/Time data type. If it's stored as text, convert it first with this formula (adjust the format string if needed):

    Created_DateTime = PARSEDATE([Created], "dd/mm/yyyy hh:mm:ss")
    
  2. Create a Row-Level Flag Column
    Add a new custom column to mark whether each row was created in the last month:

    Is_Last_Month = 
    VAR One_Month_Ago = EDATE(TODAY(), -1)
    RETURN
    IF([Created_DateTime] >= One_Month_Ago, 1, 0) // Use [Created] if it's already a Date/Time type
    
  3. Calculate the Total Count
    Now you can sum this flag column to get the total number of entries from the last month. You can do this with a measure (best for dynamic updates):

    Total_Last_Month_Entries = SUM(general_report[Is_Last_Month])
    

Key Notes

  • Dynamic vs Static: Measures are dynamic—they'll update automatically when today's date changes. The custom flag column also updates with the date, so the sum will reflect the current timeframe whenever you refresh your data.
  • Edge Cases: EDATE handles month-end correctly (e.g., if today is October 31, EDATE(TODAY(), -1) returns September 30, since September has no 31st).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 22:12:29