cancel
Showing results for
Did you mean:

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Frequent Visitor

## DAX to calculate Number of days in a week

Hi There

How to calculate number of days in a week, like,

I have attendance Table in which i want to calculate for how many days students are present for that week, Week1,2,3,4,5

in 1st week, how many students are present for 1 day,2days,3days,4 days,5 days

1 ACCEPTED SOLUTION
Community Support

Please try the following methods and check if they can solve your problem:

1.Create the simple table.

2.Using the week num and week day to create the new column.

``weeknumber = WEEKNUM('student present'[Date],2)``
``weekday = WEEKDAY('student present'[Date],2)``

3.Create the measure to calculate student.

``````student present = CALCULATE(
COUNTROWS('student present'),
FILTER(
'student present', 'student present'[IsPresent] = True
)
)``````

4.Drag the week number into the Rows, drag the weekday into the Columns and drag the measure into the matrix visual values.

Best Regards,
Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 REPLIES 5
Community Support

Please try the following methods and check if they can solve your problem:

1.Create the simple table.

2.Using the week num and week day to create the new column.

``weeknumber = WEEKNUM('student present'[Date],2)``
``weekday = WEEKDAY('student present'[Date],2)``

3.Create the measure to calculate student.

``````student present = CALCULATE(
COUNTROWS('student present'),
FILTER(
'student present', 'student present'[IsPresent] = True
)
)``````

4.Drag the week number into the Rows, drag the weekday into the Columns and drag the measure into the matrix visual values.

Best Regards,
Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Champion

To calculate the number of days each student is present in a given week, you can follow these steps using DAX (Data Analysis Expressions) in Power BI or Excel:

1. Assuming you have a table named Attendance with columns StudentID, Date, and any other relevant columns.

2. Create a calculated column to extract the week number from the date. Let's name it WeekNumber.

WeekNumber = WEEKNUM('Attendance'[Date])

Now, you can create a measure to count the number of days each student is present in each week.

DaysPresent =
CALCULATE(
COUNTROWS('Attendance'),
FILTER(
'Attendance',
'Attendance'[Presence] = "Present" && 'Attendance'[WeekNumber] = SELECTEDVALUE('Attendance'[WeekNumber])
)
)

In this measure:

• COUNTROWS('Attendance') counts the number of rows (days) in the attendance table.
• FILTER('Attendance', 'Attendance'[Presence] = "Present" && 'Attendance'[WeekNumber] = SELECTEDVALUE('Attendance'[WeekNumber])) filters the attendance table to only count the rows where the student is present and the week number matches the selected week number.

This measure will give you the count of days each student is present in the selected week. You can slice and dice the data by student and week to get the desired analysis. Make sure to replace 'Attendance', 'Presence', and other column names with the actual names from your data model.

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Frequent Visitor

Thanks for the suggestion, will try this,

Im not selecting any week No. but i want to represnt in the Stacked bar chart,  below Num are no. of students present

 Week 1Day 2 Days 3 Days 4Days 5Days 1 10 35 30 45 10 2 3 4
Community Champion

To represent the number of students present for each day of the week in a stacked bar chart in Power BI, you can follow these steps:

1. Create a New Measure for Each Day: You need to create a separate measure for each day of the week (1 Day, 2 Days, 3 Days, 4 Days, 5 Days) that calculates the count of students present for that specific number of days.

Here is an example of how you can create a measure for the count of students present for 1 day:

StudentsPresent_1Day = CALCULATE(COUNTROWS(Attendance), Attendance[WeekNumber] = SELECTEDVALUE(Attendance[Week]) && Attendance[DaysPresent] = 1)

1. You should create similar measures for 2 Days, 3 Days, 4 Days, and 5 Days, replacing the condition Attendance[DaysPresent] = 1 with the appropriate conditions for each measure.

2. Create a Stacked Bar Chart: Once you have created the measures for each day, you can create a stacked bar chart with the following settings:

• Drag the Week field to the Axis.
• Drag each measure (StudentsPresent_1Day, StudentsPresent_2Days, etc.) to the Values section of the chart.
• Ensure that the chart type is set to Stacked Bar Chart.
3. Format the Chart: You can format the chart to make it more readable and visually appealing. You may want to adjust the colors, add data labels, and provide a suitable chart title and axis labels.

By following these steps, you should be able to create a stacked bar chart in Power BI that represents the number of students present for each day of the week across different weeks. Adjust the measures and chart settings based on your specific data structure and requirements.

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Frequent Visitor

Announcements

#### Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors