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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
bron12321
Frequent Visitor

Return Date based on Conditions from same table

Hi, i've been trying to follow this: Solved: Date difference between values in same column - Microsoft Fabric Community

Since I want to get a similar result. I need to calculate the difference in days from the BaselineDate to Forecast Date for each unique ID to determine if items are running on schedule (The dataset is incomplete - not all IDs have dates set) . I have the following [Master] table: 

 

bron12321_2-1690799418341.png

with the calculated column:

DiffBaselineForcast_days =
VAR _ID = Master[UniqueID]
VAR temp =
    TOPN (
        1,
        FILTER (
            Master,
            Master[UniqueID] = _ID
                && Master[EntryType] = "ForecastDate"
        ),
        [Date], DESC
    )
RETURN
    if(Master[EntryType] = "BaselineDate",DATEDIFF(MAXX(temp,[Date]),[Date],DAY),0)

 

Which seems to be working however can someone explain it to me as I'm struggling to understand how it is working 
I'm confused with the MAXX part and that when i try and return temp[Date] it says its not a table?
or suggest a simpler way of calculating this??
Thanks!

 

1 ACCEPTED SOLUTION
bron12321
Frequent Visitor

After going away and coming back to it I've decided a new approach which I think works better:

Late2 =
VAR varCurrentScenarioID = Master[UniqueID]
VAR varCurrentEntryType = Master[EntryType]
VAR varCurrentDate = Master[Date]
VAR DateDifference =
IF(
    varCurrentEntryType = "ForecastDate",
    DATEDIFF(varCurrentDate,
        LOOKUPVALUE(Master[Date],Master[UniqueID],varCurrentScenarioID,Master[EntryType],"BaselineDate"),
        DAY),
    blank()
    )
VAR Result =  
IF(DateDifference < 0, "Late",BLANK())
RETURN
    Result

View solution in original post

1 REPLY 1
bron12321
Frequent Visitor

After going away and coming back to it I've decided a new approach which I think works better:

Late2 =
VAR varCurrentScenarioID = Master[UniqueID]
VAR varCurrentEntryType = Master[EntryType]
VAR varCurrentDate = Master[Date]
VAR DateDifference =
IF(
    varCurrentEntryType = "ForecastDate",
    DATEDIFF(varCurrentDate,
        LOOKUPVALUE(Master[Date],Master[UniqueID],varCurrentScenarioID,Master[EntryType],"BaselineDate"),
        DAY),
    blank()
    )
VAR Result =  
IF(DateDifference < 0, "Late",BLANK())
RETURN
    Result

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.