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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
hani1711
Regular Visitor

Distinct Count Based on Week Number Before Selected Week

Hello, 
I have table consist of CustomerID, TransactionDate, WeekofYear. I want to DISTINCTCOUNT the customer based on 6 weeks before current week and display it in column chart. So if the column chart 47 week should look from week 42.

My Measure like this:
TotalCust = 

CALCULATE(

DISTINCTCOUNT('CustomerID'),
WeekofYear >= MAX(WeekofYear) - 6 &&
WeekofYear <= MAX(WeekofYear)
)

I have tried like that but di value is just DISTINCTCOUNT the week in the current state. Is there anything false in my dax?

8 REPLIES 8
Anonymous
Not applicable

Hi @hani1711 

 

Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster? Thank you very much for your kind cooperation!

 

Best Regards

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

FreemanZ
Super User
Super User

hi @hani1711 ,

 

try like:

TotalCust = 

CALCULATE(

DISTINCTCOUNT('CustomerID'),

WeekofYear = MAX(WeekofYear) - 5

)

Ritaf1983
Super User
Super User

Hi @hani1711 

Please refer to the linked video:
https://www.youtube.com/watch?v=0enQCIWCSUE

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
ryan_mayu
Super User
Super User

could you pls provide some sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




hi ryan

here is the sample of data and what the expected value

hani1711_1-1733199747825.png

Example:
1. For week 47 the value should be 3, because just the 3 customer in the last 6 week based on customer in week 47, cust 004 is excluded
2. For week 47 with the filter brand A the value should be 2, with the same reason  

max week is 47 and 004 is in week 44, why not count 004 for last 6 weeks?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




because 004 isn't in week 47, the customer should be in the week 47 first before checking last 6 week

for the middle pivot table. if not in week 47, then even it exists in last 6 weeks, we don't want that. Why we need to check last 6 weeks?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.