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
Anonymous
Not applicable

Last 6 months as at dax measure for actions

Hi everyone, I have an actions table which has raised date, closed date, duedate and status fields. I need to create a visual that gives for the last 6months within SLA, overdue, 30 plus days overdue actions as at the end of the month. Within SLA actions are actions that were open as at the end of the month but not past their due date, overdue actions are actions that were open but past their due date, 30 plus overdue actions were overdue actions that were more than 30 days past their due date. Open actions definition is raised by the end of the month and status open OR status = closed, raised date before the end of the month and date closed is after the end of the month. At present the chart is generated by a SQL view which is not ideal as it does not allow slicing and dicing the visual. I would like to know if I can create a measure that would give me within SLA, overdue and 30 plus days overdue as at the end of the month based on the above conditions for the past 6 months? Thank you.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @v-shex-msft

I have managed to work it out with your help. The solution involved using the DAX measure below. The table in Power BI now matches the desired output table I posted previously. Thanks again for your support.

 

Measure 3 = 
VAR currDate =
    MAX ( dateTable[Date] )
RETURN
    SWITCH (
        SELECTEDVALUE ( Category[Type] ),
        "Raised",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] IN VALUES ( dateTable[Date] )
                 )
                )
            ,
        "Within SLA",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] <= currDate
                        && OR([CUrrentStatus] = "Open",[CUrrentStatus]="Closed"&&[DateClosed]>CurrDate) && [DUeDate]>= currDate)
                ),
        "Overdue",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] <= currDate
                        && OR([CUrrentStatus] = "Open",[CUrrentStatus]="Closed"&&[DateClosed]>CurrDate) && [DUeDate]< currDate)
                ),
        "Overdue 30 plus",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] <= currDate
                        && OR([CUrrentStatus] = "Open",[CUrrentStatus]="Closed"&&[DateClosed]>CurrDate) && [DUeDate]< currDate && DATEDIFF('Table'[DUeDate],currDate,DAY)>=30)
                )
    )

 

 

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi, as suggested here is the dummy actions data and desired output table for PBI visualisation. I need to make it a dynamic date range (ie rolling 6 months for 4 metrics listed). I have experimented with dates table joins to the raw actions table and various DAX measures based on these inactive relationships but to no avail. Again any help would be greatly appreciated.

 

Dummy raw data

 

ActionIDCUrrentStatusDateRaisedDateClosedDUeDate
1Closed16/03/202019/05/202013/08/2020
2Open24/01/2020 05/11/2020
3Open07/03/2020 31/12/2020
4Closed23/03/202031/05/202019/12/2020
5Open17/01/2020 02/07/2020
6Closed26/02/202026/04/202005/04/2020
7Open30/03/2020 08/12/2020
8Closed23/06/202029/07/202001/10/2020
9Open14/01/2020 20/12/2020
10Closed17/02/202013/06/202031/12/2020
11Closed18/06/202019/06/202003/08/2020
12Closed25/04/202014/05/202016/08/2020
13Closed13/01/202021/04/202009/12/2020
14Closed04/03/202028/03/202006/06/2020
15Closed18/02/202026/04/202021/02/2020
16Closed19/01/202025/05/202014/07/2020
17Open07/02/2020 03/11/2020
18Open07/05/2020 18/10/2020
19Closed28/06/202005/07/202019/09/2020
20Closed22/05/202001/06/202016/07/2020
21Closed23/04/202031/05/202009/07/2020
22Closed15/01/202011/05/202026/02/2020
23Open21/06/2020 01/09/2020
24Open06/02/2020 18/12/2020
25Closed17/04/202005/06/202011/11/2020
26Closed14/06/202020/06/202011/11/2020
27Closed08/06/202027/06/202012/12/2020
28Open05/03/2020 22/04/2020
29Closed25/04/202017/05/202005/06/2020
30Open29/04/2020 30/08/2020

 

Desired output table for visualisation

 

 Jan-20Feb-20Mar-20Apr-20May-20Jun-20
Raised656526
Within SLA6914161212
Overdue022211
Overdue 30 plus002111

Hi @Anonymous,

I try to create two calculated tables with date values and categories that used on matrix and write a measure formula to summary results based on the matrix category and data ranges from the raw table. You can try it if it meets your requirement.

Tables:

Category = 
DATATABLE (
    "Type", STRING,
    "Index", INTEGER,
    {
        { "Raised", 1 },
        { "Within SLA", 2 },
        { "Overdue", 3 },
        { "Overdue 30 plus", 4 }
    }
)

dateTable = 
VAR list =
    UNION (
        ALL ( 'Table'[DateClosed] ),
        ALL ( 'Table'[DateRaised] ),
        ALL ( 'Table'[DUeDate] )
    )
RETURN
    CALENDAR ( MINX ( list, [DateClosed] ), MAXX ( list, [DateClosed] ) )

Measure:

Measure = 
VAR currDate =
    MAX ( dateTable[Date] )
RETURN
    SWITCH (
        SELECTEDVALUE ( Category[Type] ),
        "Raised",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] IN VALUES ( dateTable[Date] )
                        && OR ( [DateClosed] > currDate, [DateClosed] = BLANK () )
                )
            ),
        "Within SLA",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] IN VALUES ( dateTable[Date] )
                        && [DateClosed] <= [DUeDate]
                )
            ),
        "Overdue",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] IN VALUES ( dateTable[Date] )
                        && OR ( [DateClosed] > [DUeDate], [DateClosed] = BLANK () )
                )
            ),
        "Overdue 30 plus",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] IN VALUES ( dateTable[Date] )
                        && OR ( [DateClosed] > [DUeDate], [DateClosed] = BLANK () )
                        && DATEDIFF (
                            [DUeDate],
                            MIN ( [DateClosed], MAXX ( ALL ( dateTable[Date] ), [Date] ) ),
                            DAY
                        ) >= 30
                )
            )
    ) + 0

22.png
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Hi Xiaoxin, thanks for your work on this but this is not exactly what I am looking for. Within SLA, Overdue and Overdue 30 plus measures should be up to and including the reporting month which means they should be cumulative). So for Feb for example I need to know how many actions raised up to the end of Feb were within SLA as at the end of Feb. This includes now closed actions that were open at the end of Feb (determined based on the action closed date).

Hi @Anonymous ,

Maybe you can try this one, now the formula will rolling on the date range(include previous records) based on the current date:

Measure 2 = 
VAR currDate =
    MAX ( dateTable[Date] )
RETURN
    SWITCH (
        SELECTEDVALUE ( Category[Type] ),
        "Raised",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] IN VALUES ( dateTable[Date] )
                        && OR ( [DateClosed] > currDate, [DateClosed] = BLANK () )
                )
            ),
        "Within SLA",
            COUNTROWS (
                FILTER ( 'Table', [DateRaised] <= currDate && [DateClosed] <= [DUeDate] )
            ),
        "Overdue",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] <= currDate
                        && OR ( [DateClosed] > [DUeDate], [DateClosed] = BLANK () )
                )
            ),
        "Overdue 30 plus",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] <= currDate
                        && OR ( [DateClosed] > [DUeDate], [DateClosed] = BLANK () )
                        && DATEDIFF (
                            [DUeDate],
                            MIN ( [DateClosed], MAXX ( ALL ( dateTable[Date] ), [Date] ) ),
                            DAY
                        ) >= 30
                )
            )
    )

2.png

Regards,

Xiaxoin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Hi @v-shex-msft

I have managed to work it out with your help. The solution involved using the DAX measure below. The table in Power BI now matches the desired output table I posted previously. Thanks again for your support.

 

Measure 3 = 
VAR currDate =
    MAX ( dateTable[Date] )
RETURN
    SWITCH (
        SELECTEDVALUE ( Category[Type] ),
        "Raised",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] IN VALUES ( dateTable[Date] )
                 )
                )
            ,
        "Within SLA",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] <= currDate
                        && OR([CUrrentStatus] = "Open",[CUrrentStatus]="Closed"&&[DateClosed]>CurrDate) && [DUeDate]>= currDate)
                ),
        "Overdue",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] <= currDate
                        && OR([CUrrentStatus] = "Open",[CUrrentStatus]="Closed"&&[DateClosed]>CurrDate) && [DUeDate]< currDate)
                ),
        "Overdue 30 plus",
            COUNTROWS (
                FILTER (
                    'Table',
                    [DateRaised] <= currDate
                        && OR([CUrrentStatus] = "Open",[CUrrentStatus]="Closed"&&[DateClosed]>CurrDate) && [DUeDate]< currDate && DATEDIFF('Table'[DUeDate],currDate,DAY)>=30)
                )
    )

 

 

v-shex-msft
Community Support
Community Support

Hi @Anonymous,

Please share some dummy data and expected results then we can test to coding formula on it.

How to Get Your Question Answered Quickly 
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@Anonymous , In this You need a date table joined with all dates and One join will active and others are inactive.  You can make join active using userelation.

Refer https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970

 

The best to display 6 months is relative date slicer :https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range

if not then follow this approch :https://www.youtube.com/watch?v=duMSovyosXE

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions


Appreciate your Kudos.

 

 

 

VijayP
Super User
Super User

@Anonymous 

Let me know whether this Video helps you https://www.youtube.com/watch?v=3bV9BfB3_Oc&t=1s , please share your kudoes

Vijay Perepa




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


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.