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
navedkhan
Helper III
Helper III

Calculate 'Red' Backlog Ageing with the date when it was first reported

Hi All - 

 

Am looking for URGENT help in PowerBi with calculation of Backlog (for 'Red' items only). That is if on a given date Backlog column shows 'Red' from that date till the date backlog column turns other color (Amber or Green), i need to calculate ageing from that date (excluding weekends)

 

Below is the sample data and last 2 columns is what am trying to arrive at (through DAX column)

Pls reply with DAX logic only so that i can build a loop in my table.

 

DateTeam NameBacklogFirst Occurance Date (Red)Backlog Ageing (Red)
01 Apr 19ABCRed01 Apr 191
01 Apr 19BCDGreen01 Apr 190
02 Apr 19ABCRed01 Apr 192
02 Apr 19BCDRed02 Apr 191
03 Apr 19ABCRed01 Apr 193
03 Apr 19BCDAmber -0
03 Apr 19ABCGreen -0
05 Apr 19ABCRed05 Apr 191
05 Apr 19BCDRed05 Apr 191

 

Please guide so that i can publish this report involving senior stakeholders. I have researched a lot on this community (since 3-4 days) but in vain.

 

@Zubair_Muhammad 

3 ACCEPTED SOLUTIONS

@navedkhan 

 

Try this column

 

Ageing =
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES (
            SWITCH (
                FALSE (),
                ISBLANK ( Table1[First Occurrence] ), Table1[First Occurrence],
                1
            ),
            Table1[Date]
        ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    IF ( [Backlog] = "red", COUNTROWS ( FILTER ( mydates, [Day] <= 5 ) ) )

Regards
Zubair

Please try my custom visuals

View solution in original post

@navedkhan 

 

Try this modification

 

Ageing2 =
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES (
            SWITCH (
                FALSE (),
                ISBLANK ( Table1[First Occurrence] ), Table1[First Occurrence],
                1
            ),
            Table1[Date]
        ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    IF (
        [Backlog] = "red",
        COUNTROWS (
            FILTER ( mydates, [Day] <= 5 && NOT [Value] IN VALUES ( BANKHOLIDAYS[dates] ) )
        )
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

@Zubair_Muhammad 

thanks a lot brother, it did work this time... will check on the logic for couple of days while said report is in production and revert if anything unusual crops up.

but till then many thanks ,... much appreciate. 🙂

View solution in original post

12 REPLIES 12
Zubair_Muhammad
Community Champion
Community Champion

@navedkhan 

 

Give this calculated column a shot

 

First Occurrence =
VAR Dif_Color =
    MAXX (
        TOPN (
            1,
            FILTER (
                Table1,
                [Team Name] = EARLIER ( [Team Name] )
                    && [Date] < EARLIER ( [Date] )
                    && [Backlog] <> "Red"
            ),
            [Date], DESC
        ),
        [Date]
    )
RETURN
    SWITCH (
        TRUE (),
        [Backlog] <> "Red", BLANK (),
        Dif_Color = BLANK (), MINX ( FILTER ( Table1, [Team Name] = EARLIER ( Table1[Team Name] ) ), [Date] ),
        MINX (
            FILTER (
                Table1,
                [Team Name] = EARLIER ( Table1[Team Name] )
                    && [Date] > Dif_Color
            ),
            [Date]
        )
    )

Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad 

that worked like a magic !! much appreciate..

one more request - how to calculate last column (ageing) after excluding weekends from today?

@navedkhan 

 

Try this column

 

Ageing =
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES (
            SWITCH (
                FALSE (),
                ISBLANK ( Table1[First Occurrence] ), Table1[First Occurrence],
                1
            ),
            Table1[Date]
        ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    IF ( [Backlog] = "red", COUNTROWS ( FILTER ( mydates, [Day] <= 5 ) ) )

Regards
Zubair

Please try my custom visuals



@Zubair_Muhammad wrote:

@navedkhan 

 

Try this column

 

Ageing =
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES (
            SWITCH (
                FALSE (),
                ISBLANK ( Table1[First Occurrence] ), Table1[First Occurrence],
                1
            ),
            Table1[Date]
        ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    IF ( [Backlog] = "red", COUNTROWS ( FILTER ( mydates, [Day] <= 5 ) ) )



Hi @Zubair_Muhammad 

need your small help again buddy to factor out UK Bank Holidays from the above Backlog Ageing DAX measure that you have thankfully written for me?

 

I want my Backlog Ageing to also ignore those days when there is bank holiday as per below list !!

 

DaysTheme
1New Year’s Day: Tuesday 1 January
2New Year’s Holiday: Wednesday 2 January (Scotland only)
3St Patrick’s Day: Monday 18 March (Northern Ireland only)
4Good Friday: Friday 19 April
5Easter Monday: Monday 22 April (England, Wales and Northern Ireland only)
6Early May bank holiday: Monday 6 May 
7Spring bank holiday: Monday 27 May
8Battle of the Boyne: Friday 12 July (Northern Ireland only)
9Summer bank holiday: Monday 5 August (Scotland only)
10Summer bank holiday: Monday 26 August (England, Wales and Northern Ireland only)
11St Andrew’s Day: Monday 2 December (Scotland only)
12Christmas Day: Wednesday 25 December 
13Boxing Day: Thursday 26 December

 

Possible? Please HELP ASAP.

@navedkhan 

 

 

I think you can use EXCEPT function to exclude these holidays.

Something like this

 

IF ( [Backlog] = "red", COUNTROWS ( EXCEPT(FILTER ( mydates, [Day] <= 5 ),VALUES(UKBANKHOLIDAYS)) ) )

 


Regards
Zubair

Please try my custom visuals

write a new column OR ammend existing logic you gave to me earlier?

@Zubair_Muhammad 

Ageing =
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES (
            SWITCH (
                FALSE (),
                ISBLANK ( Table1[First Occurrence] ), Table1[First Occurrence],
                1
            ),
            Table1[Date]
        ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    IF ( [Backlog] = "red", COUNTROWS ( FILTER ( mydates, [Day] <= 5 ) ) )

@zubair

@navedkhan 

 

Assuming BankHolidays are stores in a separate Table named "BankHolidays"  and column named "Dates"

 

Ageing =
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES (
            SWITCH (
                FALSE (),
                ISBLANK ( Table1[First Occurrence] ), Table1[First Occurrence],
                1
            ),
            Table1[Date]
        ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    IF (
        [Backlog] = "red",
        COUNTROWS (
            EXCEPT ( FILTER ( mydates, [Day] <= 5 ), VALUES ( BANKHOLIDAYS[dates] ) )
        )
    )

 

 


Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad 

 

It didn't work buddy. when i added that condition further to the earlier logic i get this error;

 

Error = "Each table argument of 'EXCEPT' must have the same number of columns."

 

I have added a new table with UK Public Holidays in there and tried to use that column in this nested DAX logic

 

Pls suggest a solution to counter above error?

@Zubair_Muhammad 

 

any help on this would be immensely appreciated... 

 

Anyone??

@navedkhan 

 

Try this modification

 

Ageing2 =
VAR MyDates =
    ADDCOLUMNS (
        GENERATESERIES (
            SWITCH (
                FALSE (),
                ISBLANK ( Table1[First Occurrence] ), Table1[First Occurrence],
                1
            ),
            Table1[Date]
        ),
        "Day", WEEKDAY ( [Value], 2 )
    )
RETURN
    IF (
        [Backlog] = "red",
        COUNTROWS (
            FILTER ( mydates, [Day] <= 5 && NOT [Value] IN VALUES ( BANKHOLIDAYS[dates] ) )
        )
    )

Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad 

thanks a lot brother, it did work this time... will check on the logic for couple of days while said report is in production and revert if anything unusual crops up.

but till then many thanks ,... much appreciate. 🙂

Greg_Deckler
Super User
Super User

So, you want to use EARLIER. See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.