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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
RobAdair
New Member

Help with DAX function to count items per day, for the prior day's reporting period (exc weekends)

Hello, 

 

I have a report where i am pulling a daily file of items into tables through powerquery, and then i want to build a dashboard showing the day on day change of counts of various fields (e.g. all items which are on the table per day, all items over 10 days old, etc). I then will use this data (including the measures) to build out a matrix, with Name as the rows, Report Date as columns, and the counts and measures in the values.

 

My downfall has been calculating the day on day difference. I am using a measure to count the items per day, and then i thought I'd found a really good looking piece of DAX for a further measure to store the prior business days count, where i then use a final measure to count the difference between the two. Unfortunately, the count of the prior business days seems to be randomly out on some days - and i am sure i have done something wrong! If you can advise that would be excellent!

 

 

For example

 

Table

Report DateItem IDNameIndex
08-Nov-22123456Rob9
08-Nov-22654321Steve8
07-Nov-22578132Rob7
07-Nov-22685711Andy6
07-Nov-22166664Andy5
06-Nov-22684213Steve4
06-Nov-22156651Andy3
06-Nov-22354610Rob2
06-Nov-22566451Brian1

 

Measure 1

CountPerDay = Calculate(Count('Table'[Item ID]))

 

Measure 2

Count Day-1 =
VAR __CurrentDate =
MAX ('Table'[Report Date])
VAR _LastDate =
LASTDATE(
FILTER(
ALL('Table'[Report Date]),
'Table'[Report Date] < __CurrentDate
&& NOT WEEKDAY('Table'[Report Date],2) in {6, 7}
)
)
VAR __Result =
Calculate(Count('Table'[Item ID]), _LastDate)
Return
__Result
 
Measure 3
Difference = [CountPerDay] - [Count Day-1]
 
Expected Result
 06-Nov-2207-Nov-2208-Nov-22
 CountDifferenceCountDifferenceCountDifference
Rob1 1010
Steve1 0-111
Andy 1 210-2
Brian1 0-100
1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @RobAdair 

It is recommended to create a separate calendar table and perform calculations based on this calendar table.

Count Day-1 = 
VAR _CurrentDate =
    MAX ( 'Calendar'[Date] )
VAR _LastDate =
    LASTDATE (
        FILTER (
            ALL ( 'Calendar'[Date] ),
            'Calendar'[Date] < _CurrentDate
                && NOT WEEKDAY ( 'Calendar'[Date], 2 ) IN { 6, 7 }
        )
    )
VAR _Result =
    CALCULATE ( COUNT ( 'Table'[Item ID] ), _LastDate )
RETURN
    _Result + 0

 

You may also need to check the expected result. 

07-Nov-22 is Monday, the value of difference for 07-Nov-22 should be blank as well.

 

Best Regards,
Community Support Team _ Eason

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @RobAdair 

It is recommended to create a separate calendar table and perform calculations based on this calendar table.

Count Day-1 = 
VAR _CurrentDate =
    MAX ( 'Calendar'[Date] )
VAR _LastDate =
    LASTDATE (
        FILTER (
            ALL ( 'Calendar'[Date] ),
            'Calendar'[Date] < _CurrentDate
                && NOT WEEKDAY ( 'Calendar'[Date], 2 ) IN { 6, 7 }
        )
    )
VAR _Result =
    CALCULATE ( COUNT ( 'Table'[Item ID] ), _LastDate )
RETURN
    _Result + 0

 

You may also need to check the expected result. 

07-Nov-22 is Monday, the value of difference for 07-Nov-22 should be blank as well.

 

Best Regards,
Community Support Team _ Eason

AnnieLou
New Member

I have a similar issue trying to do time intelligence day changes in ticket volumes - would be great if you can let me know if you get a solution 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.