Forum Discussion

dcheng029's avatar
dcheng029
Helper II
1 year ago
Solved

How to create calculated column that identifies date census and returns month values

Hi everyone,

 

I am working on a dataset which shows a list of job case ID and their respective date received and date closed (formatted as MM/YYYY).

 

I am wanting to create a custom column where Power BI will calculate if the ID is open at the end of each month, it will tag it as outstanding with the corresponding month (MMMM YY) name. 

 

IDDate ReceivedDate ClosedOutstanding
10001/202403/2024Jan 24, Feb 24
10101/202402/2024Jan 24
10203/202403/2024 
10304/202405/2024Apr 24
10406/202408/2024Jun 24, Jul 24
10506/202406/2024 
10608/202409/2024Aug 24
10710/202412/2024Oct 24, Nov 24
10801/202501/2025 
10903/202504/2025Mar 25
11003/202503/2025 
11103/2025 Mar 25
11204/202504/2025 
11304/2025 Apr 25
11404/202504/2025 
11504/2025 Apr 25

 

e.g. ID 100 was open in January 2024 and closed in March 2024, so as at 31/01/2024 and 29/02/2024 the job case was still open and outstanding, so the 'Outstanding' column should show the "Jan 24, Feb 24." Job cases open and closed within the same month won't have any values in the 'Outstanding' column as they would not have been open at the end of the month. Job cases open but not yet closed will follow the end of month census date (i.e. ID 111 was open in March 2025 but still open, so as at 31/03/2025 it has the Mar 25 outstanding tag. Same logic goes for ID 113 and 115 if they remain open at 31/04/2025).

 

Can someone please point me in the right direction of how to achieve this custom column on Power Query (as I then require to split this column by the comma delimiter to create graphs and visuals)? Thanks in advance.

  • Irwan's avatar
    Irwan
    1 year ago

    hello dcheng029 

     

    please check if this accomodate your need.

    create a new custom column in PQ with following code

    = Table.AddColumn(#"Changed Type", "Outstanding PQ", each if [Date Received]=[Date Closed] then "" else if Date.EndOfMonth([Date Received])=Date.EndOfMonth(Date.AddMonths([Date Closed],-1)) then Date.ToText([Date Received],"MMM yy") else Text.Combine({Date.ToText([Date Received],"MMM yy"),Date.ToText(Date.EndOfMonth(Date.AddMonths([Date Closed],-1)),"MMM yy")},", "))

     

    also as you and lbendlin said, "Split Column" only works in PQ.

    But if you have to work in DAX, you can tweak your DAX to extract a certain value using DAX such as LEFT/MID/RIGHT, PATHITEM, and i am sure there are more.

     

    Hope this will help.

    Thank you.

11 Replies

  •  

    Outstanding = 
    var c =ADDCOLUMNS(CALENDAR([Date Received],COALESCE([Date Closed],TODAY())),"m",FORMAT([Date],"MMM YY"))
    return CONCATENATEX(GROUPBY(FILTER(c,FORMAT(COALESCE([Date Closed],TODAY()),"MMM YY")<>[m]),[m]),[m],", ")

     

  • Irwan's avatar
    Irwan
    Super User

    hello dcheng029 

     

    please check if this accomodate your need.

     create a calculated column with following DAX.

    Outstanding =
    IF(
        'Table'[Date Received]='Table'[Date Closed],
        "",
    IF(
        EOMONTH('Table'[Date Received],0)=EOMONTH('Table'[Date Closed],-1),
        FORMAT('Table'[Date Received],"MMM YY"),
        FORMAT('Table'[Date Received],"MMM YY")&", "&FORMAT(EOMONTH('Table'[Date Closed],-1),"MMM YY")
    ))
    Also i am not sure ID111 has Mar25, but ID113 and ID115 have no value. All those three have blank Date Closed.
     
    Hope this will help.
    Thank you.
    • dcheng029's avatar
      dcheng029
      Helper II

      Thank you for the breakdown and the .pbix file, appreciate it.

      I am hoping to split the Outstanding column by the column delimiter so I can graph the outstanding month and case numbers together; I understand this can only be done on Power Query. Would you have any pointers on how to achieve the same output but on Power Query so I can split the column?

      • Irwan's avatar
        Irwan
        Super User

        hello dcheng029 

         

        please check if this accomodate your need.

        create a new custom column in PQ with following code

        = Table.AddColumn(#"Changed Type", "Outstanding PQ", each if [Date Received]=[Date Closed] then "" else if Date.EndOfMonth([Date Received])=Date.EndOfMonth(Date.AddMonths([Date Closed],-1)) then Date.ToText([Date Received],"MMM yy") else Text.Combine({Date.ToText([Date Received],"MMM yy"),Date.ToText(Date.EndOfMonth(Date.AddMonths([Date Closed],-1)),"MMM yy")},", "))

         

        also as you and lbendlin said, "Split Column" only works in PQ.

        But if you have to work in DAX, you can tweak your DAX to extract a certain value using DAX such as LEFT/MID/RIGHT, PATHITEM, and i am sure there are more.

         

        Hope this will help.

        Thank you.