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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Learner_44
New Member

Projected Total Expired Items by Year

Hi All,

 

I have a table of 'Items' which has a column for the Item Line each instance is part of. These item lines have expiration dates as captured in the 'Item Lines' table. What I'm trying to generate is a 100% stacked column chart for number of expired items currently and projected into future years.

 

For the following tables:

'Items'

Item IDItem LineLocation
1Line ABuilding X
2Line BBuilding X
3Line BBuilding X
4Line CBuilding X
5Line ABuilding Y
6Line ABuilding Y
7Line CBuilding Y
8Line CBuilding Y
9Line CBuilding Z
10Line CBuilding Z

 

'Item Lines'

Item LineExpiration Date
Line A5/1/2023
Line B8/7/2024
Line C1/3/2025

 

I want an output that looks like the following:

Learner_44_0-1687883763246.png

This chart was generated using the manually calculated Excel data below:

DateNum ExpiredNum Not ExpiredNotes
1/1/2023010 
1/1/202437Line A has expired
1/1/202555Lines A and B have expired
1/1/2026100All Lines are past expiration

 

Been trying to make this a single measure and then context will take care of the difference between years but can't figure it out. Thanks in advance!

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Learner_44 ,

 

Here I create a sample to have a test.

Firstly, I suggest you to create a calculated table to show years and first day of each year.

 

Year and Date =
ADDCOLUMNS ( GENERATESERIES ( 2023, 2026 ), "Date", DATE ( [Value], 01, 01 ) )

 

Measures:

 

Num Expired =
VAR _EXPIRELIST =
    CALCULATETABLE (
        VALUES ( 'Item Lines'[Item Line] ),
        FILTER (
            'Item Lines',
            'Item Lines'[Expiration Date] <= MAX ( 'Year and Date'[Date] )
        )
    )
RETURN
    COUNTAX ( FILTER ( 'Items', Items[Item Line] IN _EXPIRELIST ), Items[Item ID] ) + 0
Num Not Expired =
VAR _EXPIRELIST =
    CALCULATETABLE (
        VALUES ( 'Item Lines'[Item Line] ),
        FILTER (
            'Item Lines',
            'Item Lines'[Expiration Date] > MAX ( 'Year and Date'[Date] )
        )
    )
RETURN
    COUNTAX ( FILTER ( 'Items', Items[Item Line] IN _EXPIRELIST ), Items[Item ID] ) + 0
Note =
VAR _EXPIRELIST =
    CALCULATETABLE (
        VALUES ( 'Item Lines'[Item Line] ),
        FILTER (
            'Item Lines',
            'Item Lines'[Expiration Date] <= MAX ( 'Year and Date'[Date] )
        )
    )
VAR _COUNT =
    COUNTX ( _EXPIRELIST, [Item Line] )
VAR _ALLLIST =
    COUNTX ( ALL ( 'Item Lines'[Item Line] ), [Item Line] )
RETURN
    IF (
        _COUNT = _ALLLIST,
        "All Lines are past expiration",
        IF (
            _COUNT = 0,
            BLANK (),
            CONCATENATEX ( _EXPIRELIST, [Item Line], " , " ) & " " & "has expired"
        )
    )
Num Expired % = 
VAR _TOTAL = CALCULATE(COUNT(Items[Item ID]),ALL(Items))
RETURN
DIVIDE([Num Expired],_TOTAL)
Num Not Expired % = 
VAR _TOTAL = CALCULATE(COUNT(Items[Item ID]),ALL(Items))
RETURN
DIVIDE([Num Not Expired],_TOTAL)

 

Result is as below.

vrzhoumsft_0-1688025224737.png

 

 

Best Regards,
Rico Zhou

 

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

View solution in original post

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @Learner_44 ,

 

Here I create a sample to have a test.

Firstly, I suggest you to create a calculated table to show years and first day of each year.

 

Year and Date =
ADDCOLUMNS ( GENERATESERIES ( 2023, 2026 ), "Date", DATE ( [Value], 01, 01 ) )

 

Measures:

 

Num Expired =
VAR _EXPIRELIST =
    CALCULATETABLE (
        VALUES ( 'Item Lines'[Item Line] ),
        FILTER (
            'Item Lines',
            'Item Lines'[Expiration Date] <= MAX ( 'Year and Date'[Date] )
        )
    )
RETURN
    COUNTAX ( FILTER ( 'Items', Items[Item Line] IN _EXPIRELIST ), Items[Item ID] ) + 0
Num Not Expired =
VAR _EXPIRELIST =
    CALCULATETABLE (
        VALUES ( 'Item Lines'[Item Line] ),
        FILTER (
            'Item Lines',
            'Item Lines'[Expiration Date] > MAX ( 'Year and Date'[Date] )
        )
    )
RETURN
    COUNTAX ( FILTER ( 'Items', Items[Item Line] IN _EXPIRELIST ), Items[Item ID] ) + 0
Note =
VAR _EXPIRELIST =
    CALCULATETABLE (
        VALUES ( 'Item Lines'[Item Line] ),
        FILTER (
            'Item Lines',
            'Item Lines'[Expiration Date] <= MAX ( 'Year and Date'[Date] )
        )
    )
VAR _COUNT =
    COUNTX ( _EXPIRELIST, [Item Line] )
VAR _ALLLIST =
    COUNTX ( ALL ( 'Item Lines'[Item Line] ), [Item Line] )
RETURN
    IF (
        _COUNT = _ALLLIST,
        "All Lines are past expiration",
        IF (
            _COUNT = 0,
            BLANK (),
            CONCATENATEX ( _EXPIRELIST, [Item Line], " , " ) & " " & "has expired"
        )
    )
Num Expired % = 
VAR _TOTAL = CALCULATE(COUNT(Items[Item ID]),ALL(Items))
RETURN
DIVIDE([Num Expired],_TOTAL)
Num Not Expired % = 
VAR _TOTAL = CALCULATE(COUNT(Items[Item ID]),ALL(Items))
RETURN
DIVIDE([Num Not Expired],_TOTAL)

 

Result is as below.

vrzhoumsft_0-1688025224737.png

 

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.