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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Conditional statement open/deleted

Hi,

I'm pretty new to Power Query and I need help to implement a new column that shows if a specific OppID is open or deleted if the dataload is different from the refresh time.
Right now I have implemented this step as you can see below:

Capture.PNG

However, if the specific "OppID" is Open then the column should return "Open" for all rows that that specific OppID. Like this:
Capture1.PNG

2 ACCEPTED SOLUTIONS
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

You can use Group By on OppID, as below.

image.png

 

Add Custom Column with code as below.

image.png

And later expan back your table

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski


columns.

View solution in original post

AnkitBI
Solution Sage
Solution Sage

You can use below in Power Query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hc2xDcAwCATAXaiNBP9JwSyW918jREm6YCQa/gQ/p7gMMdccmMe9QN2eZY3X0TgbPxo/a0dGNLXYeB5/0b+jdmaEqP+z6WfTz13/ugA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [OppId = _t, DataLoad = _t, LastRefresh = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"OppId", Int64.Type}, {"DataLoad", type date}, {"LastRefresh", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"OppId"}, {{"AllRows", each _, type table [OppId=number, DataLoad=date, LastRefresh=date]}}),
    Custom1 = Table.AddColumn(#"Grouped Rows","Status",each if(Table.RowCount(Table.SelectRows([AllRows],each [DataLoad] = [LastRefresh])) > 0) then "Open" else "deleted"),
    #"Expanded AllRows" = Table.ExpandTableColumn(Custom1, "AllRows", {"DataLoad", "LastRefresh"}, {"DataLoad", "LastRefresh"})
in
    #"Expanded AllRows"

In DAX, you can add Conditional Column as below

 

Status =
IF (
    COUNTROWS (
        FILTER (
            'Table3',
            Table3[DataLoad] = EARLIER ( Table3[LastRefresh] )
                && Table3[OppId] = EARLIER ( Table3[OppId] )
        )
    ) > 0,
    "Open",
    "Deleted"
)

Thanks
Ankit Jain
Do Mark it as solution if the response resolved your problem. Do Kudo the response if it seems good and helpful.

View solution in original post

2 REPLIES 2
AnkitBI
Solution Sage
Solution Sage

You can use below in Power Query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hc2xDcAwCATAXaiNBP9JwSyW918jREm6YCQa/gQ/p7gMMdccmMe9QN2eZY3X0TgbPxo/a0dGNLXYeB5/0b+jdmaEqP+z6WfTz13/ugA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [OppId = _t, DataLoad = _t, LastRefresh = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"OppId", Int64.Type}, {"DataLoad", type date}, {"LastRefresh", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"OppId"}, {{"AllRows", each _, type table [OppId=number, DataLoad=date, LastRefresh=date]}}),
    Custom1 = Table.AddColumn(#"Grouped Rows","Status",each if(Table.RowCount(Table.SelectRows([AllRows],each [DataLoad] = [LastRefresh])) > 0) then "Open" else "deleted"),
    #"Expanded AllRows" = Table.ExpandTableColumn(Custom1, "AllRows", {"DataLoad", "LastRefresh"}, {"DataLoad", "LastRefresh"})
in
    #"Expanded AllRows"

In DAX, you can add Conditional Column as below

 

Status =
IF (
    COUNTROWS (
        FILTER (
            'Table3',
            Table3[DataLoad] = EARLIER ( Table3[LastRefresh] )
                && Table3[OppId] = EARLIER ( Table3[OppId] )
        )
    ) > 0,
    "Open",
    "Deleted"
)

Thanks
Ankit Jain
Do Mark it as solution if the response resolved your problem. Do Kudo the response if it seems good and helpful.

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

You can use Group By on OppID, as below.

image.png

 

Add Custom Column with code as below.

image.png

And later expan back your table

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski


columns.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.