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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register 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/

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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