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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sid-poly
Helper I
Helper I

CALCULATE UNIQUE COUNT FOR LAST 6 WEEKS USING DAX

I have a table that has start of week and also invoice numbers which can be carried forward to another week too

INVOICE NUMSTART OF WEEK
1232/2/2022
4561/2/2022
78931/1/2022
12328/1/2022
1018/2/2022
203

10/2/2022

789

10/2/2022

456

10/2/2022

 

Now, I want o to write a DAX that would give me the DistinctCount of All the Invoice Numbers for the last 6 Weeks. But it should distinct in every week and not overall. Let us say in the Above table 123 Invoice is a part of 2 different weeks, so the count should be 2, which means the DISTINCTCOUNT should happen on INVOICES every week and not overall.

 

I have written it as 

 

CALCULATE(DISTINCTCOUNT(INVOICE NUM),FILTER(TABLE,WEEKNUM(START OF WEEK) >= WEEKNUM(TODAY())-6 && WEEKNUM(START OF WEEK) <= WEEKNUM(TODAY())))

 

It is not doing the same as I don't get the same amount of number that I need

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @sid-poly ,

 

Try to create a measure like below:

Measure = calculate(countrows(DISTINCT(SELECTCOLUMNS('Table',"Start",'Table'[START OF WEEK],"Invoice",'Table'[INVOICE NUM]))),FILTER('Table',WEEKNUM('Table'[START OF WEEK]) >= WEEKNUM(TODAY())-6 && WEEKNUM('Table'[START OF WEEK]) <= WEEKNUM(TODAY())))

Vlianlmsft_0-1645510804006.pngVlianlmsft_1-1645510821018.png

 

 

Best Regards,
Liang
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

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @sid-poly ,

 

Try to create a measure like below:

Measure = calculate(countrows(DISTINCT(SELECTCOLUMNS('Table',"Start",'Table'[START OF WEEK],"Invoice",'Table'[INVOICE NUM]))),FILTER('Table',WEEKNUM('Table'[START OF WEEK]) >= WEEKNUM(TODAY())-6 && WEEKNUM('Table'[START OF WEEK]) <= WEEKNUM(TODAY())))

Vlianlmsft_0-1645510804006.pngVlianlmsft_1-1645510821018.png

 

 

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

Greg_Deckler
Super User
Super User

@sid-poly Maybe try:

COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER(TABLE,WEEKNUM(START OF WEEK) >= WEEKNUM(TODAY())-6 && WEEKNUM(START OF WEEK) <= WEEKNUM(TODAY()),"__Invoice",[INVOICE NUM])))


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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