Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Conditional column based on dates and value comparisons

Hello,

I have the following table loaded in Power Query. I am trying to add a new column called "Category" which would have specific text values based on the following conditions:

1. If Action date is greater than End date, then display text "Late".

2. If Action date is less than or equal to End date, then display text "On time".

3. If Status is 2, then display text "No action". This step disregards any other columns, so it depends only on the Status value.

4. Otherwise, display text "Undefined".

 

Document IDStatusStart dateEnd dateAction dateStockReturnsDefective
3998301/05/202101/06/202201/07/20226917
4050527/05/202227/06/202227/06/20222510
4050407/08/202207/09/202207/08/20225615
4052314/07/202211/08/2022 5615
4060208/08/202208/09/2022 348
4060112/08/202220/09/202222/09/20222210
4139317/08/202227/09/202223/08/20227822
4145220/08/202210/10/2022 3313
4149522/08/202202/09/202222/09/20226318
4157629/08/202209/10/202202/10/20223314
4158718/09/202215/10/2022 3314
4160207/09/202217/10/2022 2717
4160616/09/202206/10/202219/09/20223722
4164820/10/202223/11/202215/11/20229316
4166123/11/202202/12/202223/12/20227520
4187211/12/202215/01/2023 9818
4187504/01/202304/03/202317/02/20236716
4187617/02/202313/03/202301/03/202371434
4189211/12/202215/01/2023 9818

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lVRbDsMwCLtLvycVSELCWard/xojLWTutH1MGh9usDEP7Ti2Yja2x1Y8iHdqu5BwAJ1AAvQE6mEe3Lfn49gqNXLUPKSHgATQ7yDSmVCgzjqeNlZRB4ZgvbRwwS0FJFrgCkaZgfONphRuPA3qDqgbutPcQNYcEQuwhIAlgiAi2+Vi6RabEmxXCrz0s/hUDYHaUpYgjWn33933WaUkzXJPaJzkl3FNgeicW4+vYihgUNfV3mA5qCkwoh3GGXP7YTxp7z3hjHx6N1qOKu/yop0LV7wkBRobvJQQWHPWmpPH0fpu/LLA+wJrr5oCGqdy48wZCaoJbvpcUJ7K6Hk8DGlelE61cnVuYXMtaqQQVcicoCSYtycJNEenKKCfaVxAYP4nLNCvdXn7ubNh/zp/vgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document ID" = _t, Status = _t, #"Start date" = _t, #"End date" = _t, #"Action date" = _t, Stock = _t, Returns = _t, Defective = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document ID", Int64.Type}, {"Status", Int64.Type}, {"Start date", type date}, {"End date", type date}, {"Action date", type date}, {"Stock", Int64.Type}, {"Returns", Int64.Type}, {"Defective", Int64.Type}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Status] = 2 then "No action" else if [Action date] <= [End date] then "On time" else if [Action date] > [End date] then "Late" else "Undefined")
in
    #"Added Conditional Column"

 

 

I have made an attempt but it is giving me this error:

MakeItReal_1-1661356251549.png

 

MakeItReal_0-1661355938554.png

Any help is much appreciated!

 

Expected results:

Document IDStatusStart dateEnd dateAction dateStockReturnsDefectiveCategory
3998301/05/202101/06/202201/07/20226917Late
4050527/05/202227/06/202227/06/20222510On time
4050407/08/202207/09/202207/08/20225615On time
4052314/07/202211/08/2022 5615Undefined
4060208/08/202208/09/2022 348No action
4060112/08/202220/09/202222/09/20222210Late
4139317/08/202227/09/202223/08/20227822On time
4145220/08/202210/10/2022 3313No action
4149522/08/202202/09/202222/09/20226318Late
4157629/08/202209/10/202202/10/20223314On time
4158718/09/202215/10/2022 3314Undefined
4160207/09/202217/10/2022 2717No action
4160616/09/202206/10/202219/09/20223722On time
4164820/10/202223/11/202215/11/20229316On time
4166123/11/202202/12/202223/12/20227520Late
4187211/12/202215/01/2023 9818No action
4187504/01/202304/03/202317/02/20236716On time
4187617/02/202313/03/202301/03/202371434On time
4189211/12/202215/01/2023 9818No action
1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lVRbDsMwCLtLvycVSELCWard/xojLWTutH1MGh9usDEP7Ti2Yja2x1Y8iHdqu5BwAJ1AAvQE6mEe3Lfn49gqNXLUPKSHgATQ7yDSmVCgzjqeNlZRB4ZgvbRwwS0FJFrgCkaZgfONphRuPA3qDqgbutPcQNYcEQuwhIAlgiAi2+Vi6RabEmxXCrz0s/hUDYHaUpYgjWn33933WaUkzXJPaJzkl3FNgeicW4+vYihgUNfV3mA5qCkwoh3GGXP7YTxp7z3hjHx6N1qOKu/yop0LV7wkBRobvJQQWHPWmpPH0fpu/LLA+wJrr5oCGqdy48wZCaoJbvpcUJ7K6Hk8DGlelE61cnVuYXMtaqQQVcicoCSYtycJNEenKKCfaVxAYP4nLNCvdXn7ubNh/zp/vgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document ID" = _t, Status = _t, #"Start date" = _t, #"End date" = _t, #"Action date" = _t, Stock = _t, Returns = _t, Defective = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document ID", Int64.Type}, {"Status", Int64.Type}, {"Start date", type date}, {"End date", type date}, {"Action date", type date}, {"Stock", Int64.Type}, {"Returns", Int64.Type}, {"Defective", Int64.Type}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Status] = 2 then "No action" else if [Action date] = null then "Undefined" else if [Action date] <= [End date] then "On time" else if [Action date] > [End date] then "Late" else "Undefined")
in
    #"Added Conditional Column"

👍 It's been a pleasure to help you | Help Hours: 11 AM to 9 PM (UTC+05:30)

How to get your questions answered quickly -- How to provide sample data

View solution in original post

1 REPLY 1
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lVRbDsMwCLtLvycVSELCWard/xojLWTutH1MGh9usDEP7Ti2Yja2x1Y8iHdqu5BwAJ1AAvQE6mEe3Lfn49gqNXLUPKSHgATQ7yDSmVCgzjqeNlZRB4ZgvbRwwS0FJFrgCkaZgfONphRuPA3qDqgbutPcQNYcEQuwhIAlgiAi2+Vi6RabEmxXCrz0s/hUDYHaUpYgjWn33933WaUkzXJPaJzkl3FNgeicW4+vYihgUNfV3mA5qCkwoh3GGXP7YTxp7z3hjHx6N1qOKu/yop0LV7wkBRobvJQQWHPWmpPH0fpu/LLA+wJrr5oCGqdy48wZCaoJbvpcUJ7K6Hk8DGlelE61cnVuYXMtaqQQVcicoCSYtycJNEenKKCfaVxAYP4nLNCvdXn7ubNh/zp/vgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document ID" = _t, Status = _t, #"Start date" = _t, #"End date" = _t, #"Action date" = _t, Stock = _t, Returns = _t, Defective = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document ID", Int64.Type}, {"Status", Int64.Type}, {"Start date", type date}, {"End date", type date}, {"Action date", type date}, {"Stock", Int64.Type}, {"Returns", Int64.Type}, {"Defective", Int64.Type}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Status] = 2 then "No action" else if [Action date] = null then "Undefined" else if [Action date] <= [End date] then "On time" else if [Action date] > [End date] then "Late" else "Undefined")
in
    #"Added Conditional Column"

👍 It's been a pleasure to help you | Help Hours: 11 AM to 9 PM (UTC+05:30)

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.