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
saivina2920
Post Prodigy
Post Prodigy

How to get weekwise count

I have the below data. i want to get count of empno in y axis and get count weekwise of using EmpRelieve Date in x axis.

The below example shows E101A contains 3 records. we just want to eliminate like _MN and _DN, etc. we have to take only unique
value of E101A only not considering _MN like that.

So unique count of Emp No is : 5 (E101A,E102A,E103A,E104A,E105A) - Y-Axis
Weekwise count of EmpRelieve Date : (0-7, 8-14,15-21) - X-axis

How to create DAX expression and make the chart using x and y axis using the above...?

 

EmpNoEmpRelieve Date
E101A10/1/2022
E101A_MN10/1/2022
E101A_MN10/1/2022
E102A15/03/2022
E103A12/1/2022
E103A_MN12/1/2022
E103A_MN12/1/2022
E104A25/11/2021
E105A20/10/2021

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @saivina2920 , 

 

Here's my solution.

1.Create a calculated column to remove "_MN" and "_DN". 

EmpNo without MN/DN =
IF (
CONTAINSSTRING ( [EmpNo], "_MN" ) = TRUE ()
|| CONTAINSSTRING ( [EmpNo], "_DN" ) = TRUE (),
LEFT ( [EmpNo], LEN ( [EmpNo] ) - 3 ),
[EmpNo]
)

1.png

 

 

2.Create a calendar table. And sort the Year-Weeknum column by the sort column.

Calendar =
ADDCOLUMNS (
CALENDAR ( MIN ( 'Table'[EmpRelieve Date] ), MAX ( 'Table'[EmpRelieve Date] ) ),
"Year-WeekNum",
YEAR ( [Date] ) & "-"
& WEEKNUM ( [Date], 2 ),
"sort",
YEAR ( [Date] ) * 100
+ WEEKNUM ( [Date], 2 )
)

2.png

3.Create the following visual. Select "Count(Distinct)".

3.png4.png

You can check more details from my attachment.

 

 

 

Best Regards,

Stephen Tao

 

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

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @saivina2920 , 

 

Here's my solution.

1.Create a calculated column to remove "_MN" and "_DN". 

EmpNo without MN/DN =
IF (
CONTAINSSTRING ( [EmpNo], "_MN" ) = TRUE ()
|| CONTAINSSTRING ( [EmpNo], "_DN" ) = TRUE (),
LEFT ( [EmpNo], LEN ( [EmpNo] ) - 3 ),
[EmpNo]
)

1.png

 

 

2.Create a calendar table. And sort the Year-Weeknum column by the sort column.

Calendar =
ADDCOLUMNS (
CALENDAR ( MIN ( 'Table'[EmpRelieve Date] ), MAX ( 'Table'[EmpRelieve Date] ) ),
"Year-WeekNum",
YEAR ( [Date] ) & "-"
& WEEKNUM ( [Date], 2 ),
"sort",
YEAR ( [Date] ) * 100
+ WEEKNUM ( [Date], 2 )
)

2.png

3.Create the following visual. Select "Count(Distinct)".

3.png4.png

You can check more details from my attachment.

 

 

 

Best Regards,

Stephen Tao

 

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

 

It's Perfect...

AilleryO
Memorable Member
Memorable Member

Hi,

 

If you want to build a simple aquick Date Table you can use CALENDARAUTO function, which scans your model to get the start and end date of your calendar.

More info :

https://www.youtube.com/watch?v=-li7sxUxEqA&ab_channel=SQLBI

 

I do agree with speedramps, it a good practice to use a date table and it brings you a lot of possibilities.

Enjoy 

speedramps
Super User
Super User

Hi saivina2920

 

It is bad pratice to start creating your own date logic using DAX. ☹️

It is best practice to create a calendar table in Power Query with a week column

using the Date.StartOfWeek comand.

Build a Calandar once and use it always for slicing or sub totalling by week, month or year. 😀😀😀

 

Click here to watch video 

 

Please click the thumbs up and accept as solution buttons. Thank you ! 😎

Thanks for your guidance..

I am not much aware of to. Create calender table in power query..

Can you please share some samples of the above mentioned logic..

If you are giving this iit will be helpful for better understanding...

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.