Forum Discussion

rouelandrew's avatar
rouelandrew
Frequent Visitor
2 years ago

How to create clustered column chart using 2 date columns from the data table

The final result should look like this (Done using Excel) with running 12 months data up to current month.

 

The dataset has 2 columns. One has Opened Date and Closed Date. Both are Date columns with Date Heirarchies in Power BI Desktop but in the dataset itself, the month and year columns are separate for each. So there is a Opened Date, Opened Year, Closed Date, Closed Year.

 

I have 2 problems

 

1st Problem

I am able to recreate a column chart with the correct data for each column (Opened only or Closed only). Doing a few searches I see that I need to unpivot the Opened Date and Closed date columns in Power Query but when I do that and create the clustered column, the numbers no longer match.

 

How do I fix this? Data set sample at the bottom.

 

2nd Problem

The Opened in Month data is a calculated data set. The calculation is as follows

=June Opened in Month+July Opened-July Closed

 

   
 JuneJulyAugustSeptemberOctoberNovemberDecemberJanuaryFebruaryMarchAprilMayJune
Opened56861011546336 
Closed493469692968 
Open in Month27242931353736313529262424

 

How do I calculate this in DAX?

 

 Sample of how Data looks like

Customer NameUnique IDOpen YearClose YearOpened DateClose Date
ABCD11112023null10/01/2023null
ABCD11122024null11/01/2023null
ABCD11132024null12/01/2023null
ABCD11142024null01/01/2024null
ABCD1115null2023null12/01/2023
ABCD1116null2024null01/01/2024
ABCD1117null2024null02/01/2024
ABCD1118null2024null03/01/2024
ABCD11192024null02/01/2024null
ABCD11202024null03/01/2024null
ABCD1121null2024null04/01/2024

 

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi rouelandrew 

     

    1st Problem

     

     In Power Query, select the Opened Date and Closed Date columns, then use the "Unpivot Columns" option. This should transform your data into a long format, where you have a column for the attribute (Opened/Closed) and a column for the value (the actual dates).

     

     

    2nd Problem

     

    You might consider creating a measure that calculates the running total of opened cases and then subtracts the closed cases for each month. 

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • rouelandrew's avatar
      rouelandrew
      Frequent Visitor

      Hello, as mentioned in my post I did try Unpivot but when I do that the data doesn't line up or is accurate. What am I doing wrong?

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi rouelandrew 

         

        You should select both the "Open Date" and "Close date" columns for unpivot.