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
danchdrezzing
Regular Visitor

COUNT from previous day is being excluded if the COUNT for current day is 0

I have a measure that counts the number of traces for the most recent day and the day before that. The dates are always linear. Meaning, it goes from 2/21/2024 to 2/20/2024 to 2/19/2024, to 2/16/2024 - it skips weekend dates. The measures Total is correct, but the measure filters out and ShipVia that doesn't have a a COUNT for the current day. I've attached pictures, that should make more sense. I attached a picture of what the end goal is. I also included my measures below. Also, attached is the CASE WHEN for the LAG Date
End Goal.pngCurrent Table.png

--This is Current Date
Traces = 
VAR CurrentDate = MAX('Traces R5'[Trace Start Dt Alt])
RETURN 
        CALCULATE(
            COUNT('Traces R5'[Invoice]),
            FILTER(
                ALLEXCEPT('Traces R5', 'Traces R5'[Region], 'Traces R5'[ShipVia]), 
                'Traces R5'[Trace Start Dt Alt] = CurrentDate
    ))

 

--This is PreviousDate
Previous Day Traces = 
VAR CurrentDate = MAX('Traces R5'[Trace Start Dt Alt])
VAR PreviousDate = MAX('Traces R5'[LagDate])

RETURN 
        CALCULATE(
            COUNT('Traces R5'[Invoice]),
            FILTER(
                ALLEXCEPT('Traces R5', 'Traces R5'[Region], 'Traces R5'[ShipVia]), 
                'Traces R5'[Trace Start Dt Alt] = PreviousDate
            )

    )

 

    , CASE 
        WHEN LEFT(DATENAME(DW,CAST(CONVERT(CHAR(10), S.MAINTDATE, 101) AS DATE)), 3) IN ('Mon') 
            THEN DATEADD(DAY, -3, CAST(CONVERT(CHAR(10), S.MAINTDATE, 101) AS DATE))
        WHEN LEFT(DATENAME(DW,CAST(CONVERT(CHAR(10), S.MAINTDATE, 101) AS DATE)), 3) IN ('Tue', 'Wed', 'Thu', 'Fri') 
           THEN DATEADD(DAY, -1, CAST(CONVERT(CHAR(10), S.MAINTDATE, 101) AS DATE))
      END AS LagDate

 

1 REPLY 1
amitchandak
Super User
Super User

@danchdrezzing , If you are looking for Last work day

 

New columns in date table

 

Work Day = if(WEEKDAY([Date],2)>=6,0,1)
Work Date = if(WEEKDAY([Date],2)>=6,BLANK(),[Date])
Work Date Cont = if([Work Day]=0,maxx(FILTER('Date',[Date]<EARLIER([Date]) && [Work Day]<> EARLIER([Work Day]) ),[Date]),[Date])
Work Date cont Rank = RANKX(ALL('Date'),[Work Date Cont],,ASC,Dense)

 

 

Measures

 

This Day = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Work Date cont Rank]=max('Date'[Work Date cont Rank])))
Last work day = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Work Date cont Rank]=max('Date'[Work Date cont Rank])-1))
diff =[This Day] - [Last work day]

 

 

You can consider offset with allselected or previous , new Table calc

 

Power BI Offset Compare Categories, Time Intelligence MOM, QOQ, and YOY: https://youtu.be/5YMlkDNGr0U

 

🚀 Power BI Update: Visual calculations (preview)🚀
https://powerbi.microsoft.com/en-us/blog/visual-calculations-preview/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.