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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
aaa12
Helper II
Helper II

Challenging question - determine current state by month

Hello everyone, 

I have a challenging question. I have the table as below, with open date, closed date, and status...

aaa12_0-1719418152614.png

 

My goal is to show a count of items that remain open during each month and create a graph like below:

aaa12_1-1719418229661.png

 

So far the best approach I can think of is to subtract the closed date from the open date and create a matrix with a value of 1 for each month in between (screenshot below). BUT I can't figure out how to do that in DAX. Can anyone guide me here? or recommend a better solution?

 

aaa12_2-1719418324709.png

 

5 REPLIES 5
v-xinruzhu-msft
Community Support
Community Support

Hi,

Thanks for the solution @lbendlin  provided, and i want to offer some more information for user to refer to.

hello @aaa12 , based on your descriotion, you want to calculate the open items based on each month, you can refer to the following solution.

Sample data 

vxinruzhumsft_0-1719801359431.png

And i have a Calendar table, there is a 1:N relatinship relationship between tables, the key columns are open column in data table and date column in calendar table.

vxinruzhumsft_1-1719801451679.png

1.In data table create a calculated column

ClosedDate = IF([Closed]<[Open],MAXX('Calendar',[Date]),[Closed])

2.Create a measure

Open_count =
VAR _add =
    CALCULATETABLE (
        ADDCOLUMNS (
            'Table',
            "Flag",
                VAR a =
                    CALENDAR ( [Open], [ClosedDate] )
                VAR b =
                    VALUES ( 'Calendar'[Date] )
                RETURN
                    COUNTROWS ( INTERSECT ( a, b ) )
        ),
        CROSSFILTER ( 'Calendar'[Date], 'Table'[Open], NONE )
    )
RETURN
    COUNTROWS ( FILTER ( _add, [Flag] > 0 ) )

Then create a visual, and put the date column and the measure to the visual.

vxinruzhumsft_2-1719801824630.png

 

Output

vxinruzhumsft_3-1719801834471.png

 

Best Regards!

Yolo Zhu

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

 

hello - thank you for the response. Unfortunately the totals were different than actuals using the proposed solution. I went with somewhat of an inelloquent solutions by creating separate columns to evaluate each time period and then graphing it together. It works but as mentioned before, it's not so elloquent. 

 

Thank you again. 

aaa12
Helper II
Helper II

calling top authors for guidance :)! @lbendlin ; @AlienSx ...have you seen a similar use case before?

1. Do not use fake dates. Leave the close date empty and use COALESCE or a filter.

2.  You are showing by month.  Does it mean you want to count which tickets were closed on any day of the month? 

3. use a calendar table.

 

lbendlin_0-1719449590829.png

 

 

@lbendlin : Thank you...I wasn't able to reproduce it...

 

1. Do not use fake dates. Leave the close date empty and use COALESCE or a filter. (DONE)

2.  You are showing by month.  Does it mean you want to count which tickets were closed on any day of the month? (YES, just by month)

3. use a calendar table. (DONE)

 

My results....it seems the open and closed totals cancel each other out...

aaa12_0-1719459090911.png

 

My measures:

Closed

aaa12_1-1719459142795.png

Open

aaa12_2-1719459164779.png

Running Total

aaa12_3-1719459196013.png

 

My modeling relationships:

aaa12_4-1719459361245.png

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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