[英]Power BI date condition
我有兩個日期字段“MonthEndDate”和“date”我想要一個條件來滿足如果日期小於 15 則取上個月的結束日期,如果日期大於 15 則取當前月的結束日期。 例如-
|月末日期 | 日期 | 結果日期 |
6/30/1999 | 7/2/1999 | 6/30/1999
10/31/1999 | 11/1/1999 | 10/31/1999
5/31/2009 | 5/28/2009 | 5/31/2009
您可以使用電源查詢來實現此目的
let
Source = Excel.Workbook(File.Contents("C:\Ashok\Power BI\Stack Overflow\data_08_nov_21.xlsx"), null, true),
Data_Sheet = Source{[Item="Data",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Data_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"MonthEndDate ", type date}, {" date ", type date}}),
#"Inserted Day" = Table.AddColumn(#"Changed Type", "Day", each Date.Day([#" date "]), Int64.Type),
#"Added Custom" = Table.AddColumn(#"Inserted Day", "Custom", each if[Day] < 15
then Date.EndOfMonth( Date.AddMonths([#" date "], -1))
else Date.EndOfMonth([#" date "])),
#"Renamed Columns" = Table.RenameColumns(#"Added Custom",{{"Custom", "ResultDate"}})
in
#"Renamed Columns"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.