admin 管理员组文章数量: 1086019
Given a date table and a data table that contains identifies and a date:
Ident | Date |
---|---|
A | 1/05/2025 |
A | 3/02/2025 |
A | 4/15/2025 |
Given a date table and a data table that contains identifies and a date:
Ident | Date |
---|---|
A | 1/05/2025 |
A | 3/02/2025 |
A | 4/15/2025 |
Get a result like:
Year | Month | Ident | Date |
---|---|---|---|
2025 | 01 | A | 1/05/2025 |
2025 | 02 | ||
2025 | 03 | A | 3/02/2025 |
2025 | 04 | A | 4/15/2025 |
2025 | 05 | ||
2025 | 06 | ||
2025 | 07 |
Etc.
So, like how linking dated information to a Date dimension table in Power Bi will give you similar results where year/month with no data shows the year/month and blank.
Share Improve this question edited Mar 27 at 17:06 user1911400 asked Mar 27 at 13:07 user1911400user1911400 33 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 0As mentioned in comments, I am assuming there is limited set of data given in the question.
You already mentioned there is a date dimension in PowerBI which can be used.In the query below I have created a temporary date dimension for the year 2025 for each month.This date dimension can be joined with your table on year and month.
Sample query is in Snowflake since you mentioned it is going to be implemented in Snowflake.
WITH date_range AS (
SELECT DATEADD(MONTH, seq4(), '2025-01-01') AS month_start
FROM TABLE(GENERATOR(ROWCOUNT => 12)) -- 2025 for 12 months
)
,date_dim AS
(SELECT YEAR(month_start) AS Year,MONTH(month_start) AS Month
FROM date_range
)
SELECT
d.Year,d.Month,t.Ident,t.Date
FROM date_dim d
LEFT JOIN t
ON d.Year = YEAR(t.Date)
AND d.Month = MONTH(t.Date)
ORDER BY d.Year, d.Month;
Output
本文标签: t sqlUse Date table as a scaffold for dated informationStack Overflow
版权声明:本文标题:t sql - Use Date table as a scaffold for dated information - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744087024a2531318.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
date
; I hope it's not. – Thom A Commented Mar 27 at 13:16JOIN
on theYEAR
andMONTH
of the date value? Or is the problem that you're getting poor performance and want better™? – Thom A Commented Mar 27 at 13:17