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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Use Measure with previous workday

I have a simple measure:

Orders released not shipped = 

CALCULATE(
    COUNT(CD_OTTC_SHIPPING_LINE[KeyID]); CD_OTTC_SHIPPING[ISBLANK_DISPATCH_DATE] = TRUE
) 

I need this KPI for each day and the previous workday. I have a table with all previous workdays. Same day works fine. I thought i can just call this measure with my previous workday instead but dont know how to do it. It is supposed to be like the last image. Using PREVIOUSDAY() does not help since it can not take care of Holidays and weekends.

Unbenannt2.PNGUnbenannt3.PNG

Unbenannt4.PNG

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I played around a little bit with your code and came up with this solution. Seems to work now.

Test previous wd = 
VAR currDate =
    MAX (DimDate[Date])
VAR prev =
    MAX(Workdays[previous workday])
    
RETURN
    CALCULATE (
        [Orders released not shipped];
        FILTER(ALLSELECTED(CD_OTTC_SHIPPING_LINE); CD_OTTC_SHIPPING_LINE[date.OLLASTUPDDTE] = prev )
    )

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,

Please try to use following measure formula if it suitable for your requirement:

Measure =
VAR currDate =
    MAX ( 'Table'[Date] )
VAR prev =
    IF (
        WEEKDAY ( currDate, 2 ) <= 5,
        IF ( WEEKDAY ( currDate, 2 ) <> 1, currDate - 1, currDate - 3 )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Date] = prev )
    )

1.png

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

That is considering workdays and it works well! But i still have the problem with my holidays. There is no way to calculate a holiday unfortunately. I have Source with all holidays necessary. You have any suggestion on how to do this?

I came up with following idea.

Orders released previous workday not shipped = 
CALCULATE(
    [Orders released not shipped];
        FILTER(ALLSELECTED(CD_OTTC_SHIPPING_LINE); CD_OTTC_SHIPPING_LINE[OLLASTUPDDTE] = VALUES(Workdays[previous workday]) 
        ) 
)

But it only works if i chosse a single day by slicer. I cant display it for each day on a table. There will be an Error: "A table of multiple values was supplied where a single value was expected" which makes sense but i thought if i have each Date in my Reporting table PBI would only find the one value in my "Prior workday" Column.

 

 

Anonymous
Not applicable

Basicly i have to FILTER my table so that i get each  row where

[OLLASTUPDDTE].[Date]

is equal to my "previous workday". My report table would contain a current date 2019-04-23 whre my "previous workday" is the 2019-04-18 because in Germany 19-22 is a holiday. So i need all entries from my table where [OLLASTUPDDTE].[Date] = 2019-04-18. There will be several entries for this date. I could then use my Measure:

[Orders released not shipped]

Result should be my current 2019-04-23  date with my Counted rows from 2019-04-18.

Anonymous
Not applicable

I played around a little bit with your code and came up with this solution. Seems to work now.

Test previous wd = 
VAR currDate =
    MAX (DimDate[Date])
VAR prev =
    MAX(Workdays[previous workday])
    
RETURN
    CALCULATE (
        [Orders released not shipped];
        FILTER(ALLSELECTED(CD_OTTC_SHIPPING_LINE); CD_OTTC_SHIPPING_LINE[date.OLLASTUPDDTE] = prev )
    )
Greg_Deckler
Community Champion
Community Champion

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

Also, I have another Quick Measure in there called Net Work Days that shows how to handle holidays and weekends.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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