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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Junaid11
Helper V
Helper V

Condition If Date column is empty against Id

Hello,

I want to create a column in which I want if Date is there against ID then it should show Ready otherwise not ready. If ID is same and one cell has date and other opposite cell does not have the date then still it should show not ready. Below is the data:

IDDate
A123/02/2021
A118/01/2020
A2 
A201/09/2020

The outcome is below that I am looking for if ID of both rows are same and one row has date and other does not have it then it should shownot ready as below:

IDDateOutcome
A123/02/2021Ready
A118/01/2020Ready
A2 Not Ready
A201/09/2020Not Ready

It would be quite useful if you could help.

Thank you

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Junaid11 ,

Aside from merging queries like @jsaunders_zero9  has suggested is using the Table.Group function in Power Query.

  • First a custom column is created that will return 1 if [ID]  is null.danextian_1-1651626138393.png
  • Second, the whole table is grouped by [ID] so that transforms the current table into two columns: [ID] and another column with tables that contains all the records prior to grouping.
    danextian_2-1651626267200.png
  • Third, create a custom column that will sum column created in the first step per row ID. danextian_3-1651626335430.png
  • Last, expand the column of tables created in the second step to show just the date.danextian_4-1651626419468.png

     

Here 's a sample M Script to be pasted on a blank query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lEyMtY3MNI3MjAyVIrVgYoZWugbGILEDCBiRkAxBQQTKGdgCZWOBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "BlankDate", each if [Date] = null then 1 else null, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"ID"}, {{"Count", each _, type table [ID=nullable text, Date=nullable date, BlankDate=number]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Ready/Not Ready", each if List.Sum([Count][BlankDate]) <> null then "Not Ready" else "Ready", type text),
    #"Expanded Count" = Table.ExpandTableColumn(#"Added Custom1", "Count", {"Date"}, {"Date"})
in
    #"Expanded Count"

 

 

Alternatively, you can create a calculated column using DAX that will scan the table and return whether there is a blank date per row id.
danextian_5-1651626740824.png

 

 

Ready/Not Ready = 
VAR CountOfBlank =
    CALCULATE (
        COUNTBLANK ( 'Table (3)'[Date] ),
        ALLEXCEPT ( 'Table (3)', 'Table (3)'[ID] )
    )
RETURN
   IF ( CountOfBlank > 0, "Not Ready", "Ready" )
   

 

 

 

 

 

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=if(CALCULATE(COUNTBLANK(Data[Date]),FILTER(Data,Data[ID]=EARLIER(Data[ID])))=1,"Not Ready","Ready")

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
danextian
Super User
Super User

Hi @Junaid11 ,

Aside from merging queries like @jsaunders_zero9  has suggested is using the Table.Group function in Power Query.

  • First a custom column is created that will return 1 if [ID]  is null.danextian_1-1651626138393.png
  • Second, the whole table is grouped by [ID] so that transforms the current table into two columns: [ID] and another column with tables that contains all the records prior to grouping.
    danextian_2-1651626267200.png
  • Third, create a custom column that will sum column created in the first step per row ID. danextian_3-1651626335430.png
  • Last, expand the column of tables created in the second step to show just the date.danextian_4-1651626419468.png

     

Here 's a sample M Script to be pasted on a blank query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRU0lEyMtY3MNI3MjAyVIrVgYoZWugbGILEDCBiRkAxBQQTKGdgCZWOBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "BlankDate", each if [Date] = null then 1 else null, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"ID"}, {{"Count", each _, type table [ID=nullable text, Date=nullable date, BlankDate=number]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Ready/Not Ready", each if List.Sum([Count][BlankDate]) <> null then "Not Ready" else "Ready", type text),
    #"Expanded Count" = Table.ExpandTableColumn(#"Added Custom1", "Count", {"Date"}, {"Date"})
in
    #"Expanded Count"

 

 

Alternatively, you can create a calculated column using DAX that will scan the table and return whether there is a blank date per row id.
danextian_5-1651626740824.png

 

 

Ready/Not Ready = 
VAR CountOfBlank =
    CALCULATE (
        COUNTBLANK ( 'Table (3)'[Date] ),
        ALLEXCEPT ( 'Table (3)', 'Table (3)'[ID] )
    )
RETURN
   IF ( CountOfBlank > 0, "Not Ready", "Ready" )
   

 

 

 

 

 

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
jsaunders_zero9
Responsive Resident
Responsive Resident

Hi @Junaid11 

Here is a quick and easy way to acheive in PQ.

Junaid11_sample.pbix

jsaunders_zero9_0-1651616232680.png

 

Hello @jsaunders_zero9 ,

I did not mean that I have two tables. I have first table and secondl table is about expected outcome. I have millions of IDs and I cannot put each of them there one by one like you did.

Thank you

I understand what you meant, I also only have 1 table of data in the sample. The second table is derived from the first and filtered to show only ID's where there is no date and then merged back on the first.

Thank you

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.