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
Applicable88
Impactful Individual
Impactful Individual

calculate remaining workdays dynamically

Hello,

I have fact table of orders , where I fortunenately have also a column showing me the remaining workdays left, that I want to calculate againgst the revenue target in a KPI-Card. The revenue is a fix value we set up before a month starts, which for simplicity reason is not displayed in the table:

WeekdayDateOrdernumberWorkdays AccMonthYear
Tuesday28.03.202134532202103
Wednesday29.03.20214321202103
Thursday30.03.202112120202103
Friday31.03.2021345320202104
Saturday01.04.202155519202104
Sunday02.04.2021634619202104
Monday03.04.2021765719202104
Tuesday04.04.202156718202104
Wednesday05.04.2021767617202104

As you can see there is a irregularity here: the last workday of a month already belongs to the next revenue month (AccMonthYear Column). 

I need a measure for a KPI-card which calculates for me the remaining workdays of today. As also displayed in the table: if today would be the 29.03.2021 it should return "1" left workday, if today would be the 05.04.2021 it should return "17" working days left.  Datatype of AccMonthYear is just a Integer, not a Date Format. The problem is....what aggregation should be used here? There is no only()-function in PowerBi.

Thank you in advance!

Best. 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Applicable88 ,

Assuming that there is a date dimension table in your model, you can create a calculated column in orders table as follows. Please find the attachment for the details.

 

Column = 
VAR _endate =
    IF (
        'orders'[Date] = EOMONTH ( 'orders'[Date], 0 ),
        EOMONTH ( 'orders'[Date] + 1, 0 ),
        EOMONTH ( 'orders'[Date], 0 )
    )
RETURN
    CALCULATE (
        COUNTROWS ( 'Date' ),
        WEEKDAY ( 'Date'[Date], 2 ) <= 5,
        DATESBETWEEN ( 'Date'[Date], 'orders'[Date], _endate )
    )

 

yingyinr_0-1617955317148.png

I have some questions about the sample data you gave, such as Weekday and remaining workdays column. Why the workday is Wednesday instead of Monday when the date is on 05.04.2021? And why are there only 17 remaining days? How is this calculated? According to my understanding, the weekday of 05.04.2021 should be Monday, and the remaining working days are 20 days(the part with red square)...

yingyinr_1-1617955631420.png

Best Regards

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Applicable88 , check if this measure can help

 

Work Day left in month =
Var _end = eomonth(today(),0)
var _st = eomonth(today(),-1)+1
return
COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(_st,_end),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1)) -COUNTROWS(FILTER(ADDCOLUMNS(CALENDAR(_st,today()),"WorkDay", if(WEEKDAY([Date],2) <6,1,0)),[WorkDay] =1))

 

You can replace today with date of your table

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

Hello @amitchandak ,

 

I don't know why, but it doesnt't work out for me. Using the same fieldnames, but it doesn't recogznized them as field of the table.

 

Isn't there a more straightforward approach?

I know there the if-statement in PowerBi cannot distinguished single values and many values of a column when putting a column. But is something like this possible:

 

if(Table[Date]=today(), Workday)

Practically saying, if date of the table is equal today's date then return me the remaining workday from today on.

if something like this can rebuild/changed for a row to row approach?

Best.

 

Anonymous
Not applicable

Hi @Applicable88 ,

Assuming that there is a date dimension table in your model, you can create a calculated column in orders table as follows. Please find the attachment for the details.

 

Column = 
VAR _endate =
    IF (
        'orders'[Date] = EOMONTH ( 'orders'[Date], 0 ),
        EOMONTH ( 'orders'[Date] + 1, 0 ),
        EOMONTH ( 'orders'[Date], 0 )
    )
RETURN
    CALCULATE (
        COUNTROWS ( 'Date' ),
        WEEKDAY ( 'Date'[Date], 2 ) <= 5,
        DATESBETWEEN ( 'Date'[Date], 'orders'[Date], _endate )
    )

 

yingyinr_0-1617955317148.png

I have some questions about the sample data you gave, such as Weekday and remaining workdays column. Why the workday is Wednesday instead of Monday when the date is on 05.04.2021? And why are there only 17 remaining days? How is this calculated? According to my understanding, the weekday of 05.04.2021 should be Monday, and the remaining working days are 20 days(the part with red square)...

yingyinr_1-1617955631420.png

Best Regards

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.