简体   繁体   English

Power BI中带有日期的DAX条件公式

[英]DAX conditional formula with dates in Power BI

I have several columns with dates (formatted as dates in PBI modelling). 我有几个带有日期的列(在PBI建模中格式化为日期)。 Each column represents the stage ('Start' - 'Finish') I need a new column which shows at what stage each row is at. 每列代表一个阶段(“开始”-“完成”),我需要一个新列来显示每行处于哪个阶段。

So far I have this: 到目前为止,我有这个:

Procurement Stage = IF(Milestones[Close Project]<>"1/01/1900","Close 
Project",IF(Milestones[Enable The Contract]<>"1/01/1900","Enable The 
Contract",IF(Milestones[Award Contract]<>"1/01/1900","Award 
Contract",IF(Milestones[Recommend Offer]<>"1/01/1900","Recommend 
Offer",IF(Milestones[Evaluate Offers]<>"1/01/1900","Evaluate 
Offers",IF(Milestones[Implement Strategy]<>"1/01/1900","Implement 
Strategy",If(Milestones[Strategy Approval]<>"1/01/1900","Strategy 
Approval",IF(Milestones[Conduct Analysis]<>"1/01/1900","Conduct 
Analysis",IF(Milestones[Initiate Project]<>"1/01/1900","Initiate Project","Not 
Yet Started")))))))))

It comes with the following error: 它带有以下错误:

DAX comparison operations do not support comparing values of type Date with values of type Text. DAX比较操作不支持将日期类型的值与文本类型的值进行比较。 Consider using the VALUE or FORMAT function to convert one of the values. 考虑使用VALUE或FORMAT函数转换值之一。

I have double checked and ensured that all the columns are in the same format - date. 我已仔细检查并确保所有列都采用相同的格式-日期。

Can anyone help with this? 有人能帮忙吗?

I need this done in Modeling, thus I need this in DAX. 我需要在建模中完成此操作,因此我需要在DAX中完成此操作。

Thanks. 谢谢。

Evgeny 叶夫根尼·

Try: 尝试:

Procurement Stage =
VAR My_Date = DATE ( 1900, 1, 1 )
RETURN
    SWITCH (
        TRUE(),
        Milestones[Close Project] <> My_Date, "Close Project",
        Milestones[Enable The Contract] <> My_Date, "Enable The Contract",
        Milestones[Award Contract] <> My_Date, "Award Contract",
        Milestones[Recommend Offer] <> My_Date, "Recommend Offer",
        Milestones[Evaluate Offers] <> My_Date, "Evaluate Offer",
        Milestones[Implement Strategy] <> My_Date, "Implement Strategy",
        Milestones[Strategy Approval] <> My_Date, "Strategy Approval",
        Milestones[Conduct Analysis] <> My_Date, "Conduct Analysis",
        Milestones[Initiate Project] <> My_Date, "Initiate Project",
        "Not Yet Started"
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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