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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
FILIPKACZMAR
Advocate I
Advocate I

Counting days

Hello everyone!!!

 

I am new at Power BI community (learning) and I have got a little problem.

 

At my new work I got the task to repair our PowerBI dashboard.

 

I have to count days between two dates, and I wrote this code:

Obliczanie bez weekendow =
COUNTROWS (
FILTER (
ADDCOLUMNS (
CALENDAR ( 'SQA list'[End of Inspection].[Date], 'SQA list'[Delivered Report].[Date] ),
"Day of Week", WEEKDAY ( [Date], 2 )
),
[Day of Week] <> 6
&& [Day of Week] <> 7
)
)
 
And I got error, that start date could not be later than end day. In some rows it is like this, so why error is everywhere?
 
I am thinking about using IF function, to make program miss these rows. But I dont know how.
 
Can you help me?
 
Thank you very much all 🙂
1 ACCEPTED SOLUTION

Hi @FILIPKACZMAR 
Please use the following

 

=
VAR First = 'SQA list'[End of Inspection].[Date]
VAR Last = 'SQA list'[Delivered Report].[Date]
VAR First1 =
    IF ( First <= Last, First, Last - 1 )
VAR Last1 =
    IF ( First <= Last, Last, First1 )
RETURN
    COUNTROWS (
        FILTER (
            ADDCOLUMNS ( CALENDAR ( First1, Last1 ), "Day of Week", WEEKDAY ( [Date], 2 ) ),
            [Day of Week] <> 6
                && [Day of Week] <> 7
        )
    )

 

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

@FILIPKACZMAR 

Yes you can wrap CALENDAR with IF like

If ( 'SQA list'[End of Inspection].[Date] < 'SQA list'[Delivered Report].[Date],
CALENDAR ( 'SQA list'[End of Inspection].[Date], 'SQA list'[Delivered Report].[Date] ),
"Day of Week", WEEKDAY ( [Date], 2 )
))

the error will go but not sure about the results

 

THX for help, but I have got another error with code: to much argument, max for if is only 3 

:(((

@FILIPKACZMAR 

Please paste the complete code in a reply in order to check it. 

 

=
COUNTROWS (

If ( 'SQA list'[End of Inspection].[Date] < 'SQA list'[Delivered Report].[Date],
CALENDAR ( 'SQA list'[End of Inspection].[Date], 'SQA list'[Delivered Report].[Date] ),
"Day of Week", WEEKDAY ( [Date], 2 )
))

Hi @FILIPKACZMAR 
Please use the following

 

=
VAR First = 'SQA list'[End of Inspection].[Date]
VAR Last = 'SQA list'[Delivered Report].[Date]
VAR First1 =
    IF ( First <= Last, First, Last - 1 )
VAR Last1 =
    IF ( First <= Last, Last, First1 )
RETURN
    COUNTROWS (
        FILTER (
            ADDCOLUMNS ( CALENDAR ( First1, Last1 ), "Day of Week", WEEKDAY ( [Date], 2 ) ),
            [Day of Week] <> 6
                && [Day of Week] <> 7
        )
    )

 

thx for help, but it is still not working... have you got maybe 5 min to call you teams? I will send you gift from poland 🙂 

last [Date] is not collored 

FILIPKACZMAR_0-1653901218989.png

 

Whitewater100
Solution Sage
Solution Sage

Hi:

You can use DATESBETWEEN function:

For example:

DatesBtwn = DATESBETWEEN(Calendar[Date], [End of Inspection], [Delivered Report])
 
I will attach a report that shows a few examples of using either DATESBETWEEN or DATESINPERIOD. You should create a Date Table (MODELING>NEW TABLE>
and mak as Date Table and connect to Fact Table. This will allow you to do time intel calculations.
 
Date Table Code:

Dates = ADDCOLUMNS ( CALENDAR (FIRSTDATE(Sheet1[ Date]), TODAY()), "year", YEAR ( [Date] ), "MonthNumber", FORMAT ( [Date], "MM" ), "year-month", FORMAT ( [Date], "YYYY-MM" ), "month-year", FORMAT ( [Date], "MM-'YY" ) )

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors