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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
scorbin-j
Helper I
Helper I

Conditional formatting based on quantity, lead time, and date

I have a date table and a table that shows inventory transactions over time from where I have created a burndown measure for a rolling total: 

 

 

BurndownAnalysis = 
VAR LastConvertedQty = 
    CALCULATE(
        LASTNONBLANK(
            Burndown[quantity], 
            CALCULATE(MAX(date[Date]))
        )
    )
RETURN
    IF(
        ISBLANK(
            CALCULATE(
                SUM(Burndown[quantity]),
                FILTER(
                    ALLSELECTED(date[Date]]),
                    ISONORAFTER(
                        date[Date], 
                        MAX(date[Date]), 
                        DESC
                    )
                )
            )
        ),
        LastConvertedQty,
        CALCULATE(
            SUM(Burndown[quantity]),
            FILTER(
                ALLSELECTED(date[Date]),
                ISONORAFTER(
                    date[Date], 
                    MAX(date[Date]), 
                    DESC
                )
            )
        )
    )

 

 

I also have material table that shows lead time for each material. I would like to format the quantities from the burndown measure so that when the quantity goes to 0 or below it's red and then yellow for the quantities under the dates that are within the lead time of the date when the quantity goes to zero. I think this means I need to find the "zero quantity date" for each material, but I'm not sure how to do that. And then calculate the dates that are within the lead time of the "zero quantity date".

Example:

scorbinj_0-1725647783756.png


I would also note that the quantites are summed by week in my visual. 

1 ACCEPTED SOLUTION
scorbin-j
Helper I
Helper I

Figured it out: 

VAR LastConvertedQty = 
    CALCULATE(
        LASTNONBLANK(
            Burndown[quantity], 
            CALCULATE(MAX(date[Date]))
        )
    )
VAR _burn =
    IF(
        ISBLANK(
            CALCULATE(
                SUM(Burndown[quantity]),
                FILTER(
                    ALLSELECTED(date[Date]),
                    ISONORAFTER(
                        date[Date], 
                        MAX(date[Date]), 
                        DESC
                    )
                )
            )
        ),
        LastConvertedQty,
        CALCULATE(
            SUM(Burndown[quantity]),
            FILTER(
                ALLSELECTED(date[Date]),
                ISONORAFTER(
                    date[Date], 
                    MAX(date[Date]), 
                    DESC
                )
            )
        )
    )

VAR _material = 
    SELECTEDVALUE(MaterialMaster[Material_Master])

VAR LeadTime =
    LOOKUPVALUE(
        MaterialMaster[LeadTime], 
        MaterialMaster[Material_Master], _material
    )

VAR _zerodate =
CALCULATE (
    CALCULATE (
        MIN ( date[Date] ),
        FILTER (
            ALL ( dimTime ),
            [BurndownAnalysis] <= 0
                && date[Date] > TODAY ()
        )
    ),
    FILTER (
        ALL (MaterialMaster),
        MaterialMaster[material_master] = _material
    )
)

VAR LeadTimeWindow = _zerodate - LeadTime

RETURN 
    IF(
        _burn <= 0, 
        1, // Red
        IF(
            _burn > 0 && MAX(date[Date]) >= LeadTimeWindow && MAX(date[Date]) <= _zerodate, 
            2, // Yellow
            3  // Green
        )
    )

View solution in original post

1 REPLY 1
scorbin-j
Helper I
Helper I

Figured it out: 

VAR LastConvertedQty = 
    CALCULATE(
        LASTNONBLANK(
            Burndown[quantity], 
            CALCULATE(MAX(date[Date]))
        )
    )
VAR _burn =
    IF(
        ISBLANK(
            CALCULATE(
                SUM(Burndown[quantity]),
                FILTER(
                    ALLSELECTED(date[Date]),
                    ISONORAFTER(
                        date[Date], 
                        MAX(date[Date]), 
                        DESC
                    )
                )
            )
        ),
        LastConvertedQty,
        CALCULATE(
            SUM(Burndown[quantity]),
            FILTER(
                ALLSELECTED(date[Date]),
                ISONORAFTER(
                    date[Date], 
                    MAX(date[Date]), 
                    DESC
                )
            )
        )
    )

VAR _material = 
    SELECTEDVALUE(MaterialMaster[Material_Master])

VAR LeadTime =
    LOOKUPVALUE(
        MaterialMaster[LeadTime], 
        MaterialMaster[Material_Master], _material
    )

VAR _zerodate =
CALCULATE (
    CALCULATE (
        MIN ( date[Date] ),
        FILTER (
            ALL ( dimTime ),
            [BurndownAnalysis] <= 0
                && date[Date] > TODAY ()
        )
    ),
    FILTER (
        ALL (MaterialMaster),
        MaterialMaster[material_master] = _material
    )
)

VAR LeadTimeWindow = _zerodate - LeadTime

RETURN 
    IF(
        _burn <= 0, 
        1, // Red
        IF(
            _burn > 0 && MAX(date[Date]) >= LeadTimeWindow && MAX(date[Date]) <= _zerodate, 
            2, // Yellow
            3  // Green
        )
    )

Helpful resources

Announcements
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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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